Migrate ESXi virtual machines to a different datastore using PowerCLI
I needed to perform a bulk move of all the virtual machines running on an ESXi Host to a NAS storage device so that I could rebuild the RAID array. Needed an easy way to perform this move, so i used powerCLI and it was very easy.
The following PowerCLI script will do this. It will even perform a storage vMotion if the VM is running but only if there are no snapshots.
Get-VMHost -Name <ESXi Host> | Get-VM | Move-VM -Datastore <NFS Datastore>
replace the <ESXi Host> and <NFS Datastore> with your values.
After the datastore move was completed I removed all the vms from inventory using vSphere Client.