Skip navigation

Use Plink to Reboot VMware VMs

Plink is fast, effective, and free

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 stop
exit 

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 start
exit 

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

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish