Hi there,
I'm trying to build a powercli script to perform the following actions:
Poweroff a list of VMs
VMotion to the new hosts
Upgrade VM Hardware and tick the VMware Tools upgrade at next power cycle box
SVMotion the VMs to the storage
Start up the VMs
The problem I'm getting is when the SVMotion is started the script doesn't wait for it to finish to start up the VMs. I tryied with the Wait-Task, but the problem is that the Move-VM task itself finishes but the SVMotion is still running.
Can someone help me here please.
Thanks
This is the script I'm using: (please note I'm new to powerCLI)
# List of VMs to move and Upgrade
$vms = Import-CSV "C:\tmp\list_of_vms.csv"
# Shutdown gracefully and wait for Power Off state
foreach ($vm in $vms){
Get-VM -Name $vm.name | Shutdown-VMGuest -Confirm:$false
}
do {} until ((Get-VM $vm.name | select PowerState).powerstate -eq "PoweredOff")
# VMotion VMs to the new Cluster and Upgrade Hardware Version and VMware Tools
foreach ($vm in $vms){
Move-VM -VM $vm.name -Destination $vm.targetHost -RunAsync
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
Get-View -ViewType VirtualMachine | %{
$_.ReconfigVM($vmConfigSpec)
}
Set-VM -VM (Get-VM -Name $vm.name) -Version v11 -Confirm:$false -RunAsync
Move-VM -VM $vm.name -Datastore $vm.targetDataStore -RunAsync
Start-VM -VM $vm.name -Confirm:$false -RunAsync
}