I am having trouble getting the system to shutdown and wait till it is actually in a state to make changes. I get errors "the system is not a state... "
I think the issue is there is a delay from when the system shuts down to when you can actually make a change, such as number of processors.
Is there a better way than what I am trying below?
Get-VM -name $VMName* | Shutdown-VMGuest -Confirm:$false
if ($VMName.PowerState -eq "PoweredOn") {
Write-Host "Shutting Down" $VMName
Shutdown-VMGuest -VM $VMName
#Wait for Shutdown to complete
do {
#Wait 5 seconds
Start-Sleep -s 5
$status = $VMName.PowerState
}until($status -eq "PoweredOff")
}