Last active
February 5, 2018 19:09
-
-
Save phwelo/92c3e45b144bba8f4bca1229d5f7fd4d to your computer and use it in GitHub Desktop.
[ConfirmShutdown] Powershell function that manually waits for machine to power off. #powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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