Hello,
I need to;
1) Shutdown all VMs running on ESXi host
2) Then shutdown that ESXi host
How to achieve this via SSH?
Thanks.
I've found it a lot easier to do this via PowerCLI...
$vc = vcenter1
$dc = "Datacenter"
Connect-VIServer $vc
# Gets the list of all VMs in the datacenter (except the vCenter VM itself)
$vms = Get-datacenter -Name $dc | Get-VM | where {$_.Name -ne $vc -and $_.PowerState -eq "PoweredOn"}
# Shuts down the VMs in the datacenter that are in a powered on state.
Foreach ($vm in $vms){
if($vm.ExtensionData.Config.Tools.ToolsVersion -ne "0"){
#gracefully shutdown
Shutdown-VMGuest -VM $vm -Confirm:$false
sleep -Seconds 60
}
#forcefully stopping VM
Stop-VM -VM $vm -Confirm:$false
}
# Shutdown vCenter VM (Comment out if vCenter is not virtual)
sleep -seconds 120
Shutdown-VMGuest -VM $vc-Confirm:$false
Hi,
You should really shut down the VMs gracefully, but if you wanted to force shutdown then have a look at this KB VMware KB: Powering off a virtual machine on an ESXi host
You can shutdown host using DCUI - VMware KB: ESXi/ESX 4.x and ESXi 5.x/6.0 shutdown and reboot commands
Here is how I would do it, running commands from the vMA:
1.) vmware-cmd --server <esxi_hostname> -l
2.) loop though the above output, and ssh in to each VM, and issue the shutdown command.
You would have no need to shut down the VM; it should show as powered down once the OS shuts down.
I need to do from PUTTY, how to do that?
Thanks.
PuTTY is just another terminal program for connecting to remote servers via SSH (or other protocols). This is not the place to learn how to use PuTTY or SSH. In brief, you would already have an open PuTTY terminal, with an SSH connection to your vMA. From that shell prompt is where you would run your vmware-cmd command and then ssh in to all the other servers. Ideally you'd have ssh keys set up on the remote servers so that you don't have to type your password each time.
Here is another way to do it that does not require SSH at all, just the vMA & the vi Perl Toolkit:
vmcontrol.pl --server <vCenter> --username <UID> --vmname <vm> --operation shutdown
I've found it a lot easier to do this via PowerCLI...
$vc = vcenter1
$dc = "Datacenter"
Connect-VIServer $vc
# Gets the list of all VMs in the datacenter (except the vCenter VM itself)
$vms = Get-datacenter -Name $dc | Get-VM | where {$_.Name -ne $vc -and $_.PowerState -eq "PoweredOn"}
# Shuts down the VMs in the datacenter that are in a powered on state.
Foreach ($vm in $vms){
if($vm.ExtensionData.Config.Tools.ToolsVersion -ne "0"){
#gracefully shutdown
Shutdown-VMGuest -VM $vm -Confirm:$false
sleep -Seconds 60
}
#forcefully stopping VM
Stop-VM -VM $vm -Confirm:$false
}
# Shutdown vCenter VM (Comment out if vCenter is not virtual)
sleep -seconds 120
Shutdown-VMGuest -VM $vc-Confirm:$false