Skip to content

Instantly share code, notes, and snippets.

@phwelo
Last active February 5, 2018 19:09
Show Gist options
  • Save phwelo/92c3e45b144bba8f4bca1229d5f7fd4d to your computer and use it in GitHub Desktop.
Save phwelo/92c3e45b144bba8f4bca1229d5f7fd4d to your computer and use it in GitHub Desktop.
[ConfirmShutdown] Powershell function that manually waits for machine to power off. #powershell
function ConfirmShutdown($VM) {
$TimeOut = New-TimeSpan -Minutes 5
$StopWatch = [diagnostics.stopwatch]::StartNew()
while ($StopWatch.elapsed -lt $TimeOut) {
$VM = Get-VM -name $VM
if ($VM.PowerState -eq 'PoweredOff') {
write-host 'Cool'
return
}
for ($i=0; $i -le 4; $i++) {
write-host -NoNewline '.'
start-sleep -seconds 1
}
}
write-warning "Timeout error on shutdown of $VM"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment