PowerCLI – Storage vMotion VMs from One Datastore to Another

SCRIPT SYNOPSIS / REASON CREATED – We are doing a good bit of underlying infrastructure work on our SAN environments, so we needed a script to move all VMs from an “old” datastore to a “new” (or different) datastore. Additionally, many of our VMs had been created as “thick provisioned eager zero” (before my arrival), so I wanted to use this opportunity to “thin provision” all of the VMs when I performed the Storage vMotion. As I looked for scripts to assist with this, I was amazed as how easy this is with just a few steps.

 

OVERVIEW OF STEPS – This is a very simple script that connects to your vCenter with the supplied credentials and then moves all VMs from one datastore to another datastore, while changing each VM to “thin provisioned” during the process. For my environment, I added the “-RunAsync” option at the end of the command so as to have all sVmotions running at the same time. If you want to run the sVmotions singularly (wait until one sVmotion is complete before starting another one), you can remove the “-RunAsync” option from the command.