Use Plink to Reboot VMware VMs

Plink is fast, effective, and free

Readers

January 21, 2009

2 Min Read
ITPro Today logo

In our data center, we use VMware's Virtual Infrastructure 3.0. Recently, I was looking for a way to programmatically power cycle (i.e., turn off and turn back on) a virtual machine (VM) from a remote Windows host. I came across a free utility named Plink, which is essentially a command-line interface for PuTTY, an open-source Secure Shell (SSH) and Telnet client.

I decided to try Plink. After I downloaded it from the PuTTY Download Page, I used Plink to issue the command

plink.exe -load "ESXservername" -ssh -batch -l ESXusername -pw ESXpassword -m stopscript 

where

  • ESXservername is the name of the VMware ESX Server host on which the VM resides.

  • ESXusername is the name of the account that has the right to power cycle the VM. (As a security precaution, this account should only have right to power cycle specific VMs and no other rights.)

  • ESXpassword is the password for the account that has the right to power cycle the VM. (For better security, you can use public key encryption and store your private keys in a free associated application named Pageant available from the PuTTy Download Page.)

  • stopscript is the name of text file that contains the shutdown commands to be executed.

The stopscript file contained the commands

/usr/bin/vmware-cmd /vmfs/volumes/DataStoreName/VMName/VMName.vmx stopexit 

where DataStoreName is the friendly name of the VMware File System (VMFS) data store and VMName is the name of the VM to shut down.

To start the VM back up, I used the command

plink.exe -load "ESXservername" -ssh -batch -l ESXusername -pw ESXpassword -m startscript 

where startscript is the name of text file that contains the startup commands to be executed. Those commands were

/usr/bin/vmware-cmd /vmfs/volumes/DataStoreName/VMName/VMName.vmx startexit 

The ability to shutdown and restart a guest OS gracefully has been extremely useful. It lets us programmatically reboot servers in isolated certification environments and power off VMs that are required only during certain hours. This method has proved more flexible than scheduling tasks in VMware vCenter Server (formerly VMware VirtualCenter) because we can use the scripts with third-party schedulers and in conjunction with other scheduled tasks, such as SAN replication. Overall, Plink has been an invaluable utility that has provided us an efficient means of programmatically accessing our ESX infrastructure.

—Brent McCraney, senior technical analyst, Ontario Teachers' Pension Plan

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like