Restart Multiple VM’s

 Connecting to individual host

Open VMware vSphere PowerCLI console

#Connect to the host
Connect-VIServer -Server hostname.example.com

#Get all VMs from the host, filter those powered on and shut them down
Get-VM | Where-Object {$_.powerstate -eq ‘PoweredOn’} | Shutdown-VMGuest -Confirm:$false

Connecting to vCenter

If you connect to vCenter, you have more options. You can target a single host, a cluster, a datacenter or the whole vCenter.

If you need to shutdown all VMs in the vCenter, virtu-al.net has a nice script.

First connect to your vCenter

Connect-VIServer -Server vCenter.example.com
Shutdown all VMs in a host

#Get all VMs from the host, filter those powered on and shut them down
Get-VMHost “hostname.example.com” | Get-VM | Where-Object {$_.powerstate -eq ‘PoweredOn’} | Shutdown-VMGuest -Confirm:$false
Shutdown all VMs in a cluster

#Get all VMs from the cluster, filter those powered on and shut them down
Get-Cluster “Cluster1” | Get-VM | Where-Object {$_.powerstate -eq ‘PoweredOn’} | Shutdown-VMGuest -Confirm:$false
Shutdown all VMs in a datacenter

#Get all VMs from the datacenter, filter those powered on and shut them down
Get-DataCenter “DC1” | Get-VM | Where-Object {$_.powerstate -eq ‘PoweredOn’} | Shutdown-VMGuest -Confirm:$false
For one reason or the other, VMs refuse to shutdown gracefully. If you have a stuck VM, use Stop-VM to force poweroff.

Eg-

Get-VM | Where-Object {$_.powerstate -eq ‘PoweredOn’} | Stop-VM -Confirm:$false

#Restart VM from Text File

get-content c:\Temp\ServerList.txt | foreach-object { Restart-VM $_ -Confirm:$false}

#check poweron status

get-content c:\Temp\ServerList.txt | foreach-object { Where-Object {$_.powerstate -eq ‘PoweredOn’}}
get-content c:\Temp\serverlistvm.txt | foreach-Object {$_.powerstate -eq ‘PoweredOn’}|Shutdown-VMGuest $_ -Confirm:$false
get-content c:\Temp\serverlistvm.txt | foreach-Object {Stop-VM $_ -Confirm:$false}

14 Comments

  1. Howdy! I just want to give an enormous thumbs up for the great data you will have here on this post. I might be coming again to your blog for more soon.

  2. This is really interesting, You’re a very skilled blogger. I’ve joined your feed and look forward to seeking more of your magnificent post. Also, I’ve shared your web site in my social networks!

  3. Can I simply say what a relief to seek out someone who truly knows what theyre talking about on the internet. You positively know methods to carry a difficulty to mild and make it important. Extra individuals have to read this and perceive this side of the story. I cant consider youre no more widespread because you undoubtedly have the gift.

  4. What’s Happening i’m new to this, I stumbled upon this I’ve discovered It positively helpful and it has aided me out loads. I am hoping to give a contribution & aid other users like its helped me. Great job.

  5. I found your weblog web site on google and examine just a few of your early posts. Continue to keep up the superb operate. I simply extra up your RSS feed to my MSN Information Reader. Seeking forward to reading more from you later on!…

  6. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  7. I do enjoy the manner in which you have presented this specific concern plus it does supply me some fodder for consideration. On the other hand, from what I have personally seen, I really hope as the actual comments pack on that people today stay on issue and don’t start upon a tirade of the news du jour. Anyway, thank you for this superb point and although I can not go along with the idea in totality, I value the standpoint.

Leave a Reply

Your email address will not be published.