PowerShell for Windows Admins

Feb 17 2015   1:37PM GMT

Shutting down machines in parallel

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:
Hyper-V
Powershell

My test lab is a set of virtual machines running on a Lenovo w1510 laptop. When I’ve finished working for the day I want to shut down the virtual machines and the laptop. I may have anywhere between 2 and 8 (or more) VMs running so scripting the shutdown helps a lot.

Machines can be shutdown independently so this is an action that is ideal for parallel execution through a workflow.

workflow stop-allvms {
$vms = Get-VM | where State -eq “Running”
foreach -parallel ($vm in $vms) {
Stop-Computer -PSComputerName $vm.Name -Force -Verbose
}
}

stop-allvms

Get the running VMs. use foreach –parallel to run stop-computer against each VM. Notice I’ve had to change the parameter on Stop-Computer from –ComputerName to –PSComputerName

Another little workflow that makes life easier. I looks like workflows aren’t going to be the game changer that we originally thought but they do add some interesting options.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: