We ran into an issue where we needed an entire SAN frame retired. Problem is, there are several datastores and several guests running on that frame.

I wanted to script it out, which worked just fine. Then, we had more to do, so I edited the script and ran it again. After the third or fourth time, I decided to write a script that takes params via the cli.

Make sure your datastore names are similar, for instance, mine appends ‘_New’ to the end. So my datastores have to be named like this: ‘vmdatastore’ and ‘vmdatastore_New’. It will get all guests on the datastore and migrate them one by one over to the new datastore. When done, just delete the old datastore (or rename it to _Old) and rename the new one to match.

My script:

Then, to run it, I simply type this (after saving the file as Migrate-Storage.ps1):

Migrate-Storage -vc vcenterserver -datastores (“datastore1″,”datastore2″,”datastore3”)

This will check datastore1, get all VMs, migrate them to datastore1_New, then move on to the next datastore.