PowerShell Script that shuts down all running virtual machines on named Hyper-V server. It shuts them down one at a time waiting while a VM shuts down before shutting down the next. Remember to substitute your <servername>. Quick way to shutdown the test environment at the end of the day.
$runningVM=Get-VM –ComputerName <servername> | Where-Object {$_.State -eq 'Running'}
foreach($cn in $runningVM){
Write-Host "Shutting down $($cn.name)"
stop-vm $cn.name -force
}
Add the following lines to shut down the Hyper-v server
Write-Host "Shutting down Hyper-V server”
Stop-Computer –computername <servername> –force
No comments:
Post a Comment