
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