Dear all,
I would like to know what's the best practice to shutdown all VM as quickly as possible (With shutdown guest os command if possible) by using vsphere ?
Indeed, the past week I had a power failure and I needed more than 10 minutes to stop all vm manually that's too much.
Is there any fonction to do that or a script ?
Thanks in advance.
I currently don't have access to a host to verify this, but you should be able to select all running VM's from the vSphere Client in the ESXi host's "Virtual Machines" tab, and select Shut Down from the pop-up menu (assuming VMware Tools are installed in the VMs).
André
Thanks but shutdown guest os is not available while vmtools are installed on both VM:
Hi Zemo,
Do you want to shutdown VM in specific ESXi host or entire vCenter?
If you want to shutdown in ESX have a look at Ducan's Blog shutdown all vm's and ESX - Yellow Bricks..Try the script at testing environment and then to production.
Hi,
As everyone know that Command Line is best tool for doing thing fast.
To Shutdown a VM or a Group of VM you can use the following Command
Shutdown-VMGuest [[-VM] <VirtualMachine[]>] [[-Server] <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Shutdown-VMGuest [[-Guest] <VMGuest[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Example 1
Get-VM VM | Shutdown-VMGuest
for more Information vSphere 5.5 Documentation Center
Hi,
You can use the following few lines to shut down the guest operating systems gracefully as long as VMware Tools is installed. Open PowerCLI and connect to your VMware vCenter server by typing “Connect-VIServer vCenterServerName”.
To shutdown all VM guest managed by vCenter you can type the following 3 lines:
$vmservers=Get-VM | Where-Object {$_.powerstate -eq ‘PoweredOn’}
$vmservers | select Name | export-csv c:\MyScripts\servers.csv -NoTypeInformation
$vmservers| Shutdown-VMGuest
The script above will do 3 things. The first line will get all VMs that are currently powered on. The second line will log all the powered on VMs in line 1 and log them to a csv file servers.csv located in c:\MyScripts. The reason I log these machine names to a csv file is so when it’s time to turn the machines back on, I don’t inadvertently turn on any VMs that were turned off for whatever reason before I began the shutdown. The third line will shutdown the Vmware guests. The third line will ask you for confirmation before doing anything. If you don’t want to be asked for confirmation, you can simply add “-Confirm:$false” as shown below:
$vmservers | Shutdown-VMGuest -Confirm:$false
I was actually thinking of the Windows based vSphere Client rather than the Web Client.
André
On small networks, I used plink (part of putty):
plink.exe -ssh 10.10.11.33 -l root -pw password /sbin/vmware-autostart.sh stop
This only stops automatically started VMs. To quote shutdown.sh:
#Power off autostart configured VMs
/sbin/vmware-autostart.sh stop
I am still trying to figure out how to use SSH keys with WinSCP and putty, as documented here.
You can write functions like this:
function Start-SR4 {
start-vm -VM PRIM-SERVER,SEC-SERVER -RunAsync
start-sleep -Seconds 30
start-vm -VM CLIENT1,CLIENT2,CLIENT3,CLIENT4 -RunAsync
}
function Stop-SR4 {
Stop-VMGuest -Confirm:$false -VM CLIENT1,CLIENT2,CLIENT3,CLIENT4
start-sleep -Seconds 30
Stop-VMGuest -Confirm:$false -VM PRIM-SERVER,SEC-SERVER
}
This leverages the previous reply with the command line info.
The delay is in case you need time for the clients to disconnect from the servers.
Does anyone know why the -Confirm switch requires the colon as in -Confirm:$false, instead of -Confirm $false?
This gave me some trouble.
Easy and Effective solution in PowerCLI to Shutdown VMs with one click:
First LOGON into the vCenter from locally/remotely PowerCLI
Connect-VIServer -server YouvCenterServerName
PASTE,
get-content c:\cli\vm.txt | foreach-object { shutdown-vmguest $_ }
Press ENTER > DONE!
EXAMPLE:
C: Is your local C:\ Drive
CLI: You need to create a folder in the C: Drive & name it "cli" or anything you want
VM.TXT: then create a txt file & input all the VM names in it. EX:
VM1
VM2
VM3
Your can also Kill the VMs from the ESXi host
You better post your quest about PowerCLI @ VMTN Forum > Automation Tools > VMware PowerCLI for better answers!!!
Raul.
VMware VDI Administrator
Could not use Powershell scripts even after reading a lot about loading snap-ins/modules but I probably missed something. 😕
So I installed VMware-vSphere-CLI (version 5.5.0 for me) so I had the vmware-cmd.pl script and commands so that I could run the following DOS script by a scheduled task :
cd /D "C:\Program Files (x86)\VMware\VMware vSphere CLI\bin"
set login=-H myserver -U root -P mypassword
rem vmware-cmd.pl %login% -l to get the VM raw name
set vm=/vmfs/volumes/53b17247-36fb17f7-93f8-002590534d58/VM/VM.vmx
rem If I can get the VMtools status, the OS runs in the VM, so I shutdown the guest. Otherwise, I only have to hard shutdown the VM.
vmware-cmd.pl %login% %vm% gettoolslastactive | findstr /C:"= 0"
if %ERRORLEVEL% == 0 (
vmware-cmd.pl %login% %vm% stop hard
) else (
vmware-cmd.pl %login% %vm% stop
)