VMware Cloud Community
Pflynn
Contributor
Contributor

Total shutdown options

Hello,

I have seen a few pieces here about shutting down guests and hosts. I have an ancient UPS that will send a signal to windows only to shutdown. I am allowed to launch a bat/cmd file .I was wondering if it is feasible to use the powershell toolkit to connect to VC, and for each host there - shutdown all running vms followed by shutdown the host.

My plan, so far is :

http://geekswithblogs.net/Lance/archive/2007/02/16/106518.aspx

gets me to logn without clear text credentials

PowerShell -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\mysettings.psc1" -command .\powerdown.ps1

Thepowershell script would have

something that lists vm'guests on host| shutdown-vmguest should get my vm's powered down

get-viserver -server $HS = Find-EntityView -ViewType "HostSystem" $HS.ShutdownHost("false")

This gets my host shutown

Is there a way to list all hosts attached to VC? I'd like to make it so that each host added later behaves the same way without having to add to the script.

Advice/experience appreciated

Regards

Paul Flynn

0 Kudos
1 Reply
LucD
Leadership
Leadership

The cmdlet Get-VMHost dynamically returns all ESX hosts known in your VC.

There is no VI Toolkit cmdlet for stopping an ESX server but you can use the ShutdownHost_Task method of the HostSystem object.

Get-VMHost | %{Get-View $_.ID} | %{$_.ShutdownHost_Task($TRUE)}

The Get-View cmdlet is needed to convert the object to a HostSystem object on which we can execute the ShutdownHost_Task method.

The Boolean parameter to the method says whether or not the host should be shut down regardless of whether it is in maintenance mode.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference