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}
dfjwje
oy8264
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.
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!
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.
0mysxt
ug80r3
xoboa4
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.
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!…
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!
As soon as I discovered this internet site I went on reddit to share some of the love with them.
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.
you’ve got an incredible blog right here! would you wish to make some invite posts on my blog?
jg069i
Perfectly written subject material, Really enjoyed examining.
I visited a lot of website but I believe this one has something extra in it in it
Some really great content on this site, regards for contribution. “When he has ceased to hear the many, he may discern the One – the inner sound which kills the outer.” by H Hahn Blavatsky.
Howdy! I’m at work browsing your blog from my new iphone 3gs! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the superb work!