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

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottYou'll have the opportunity to experience:
• The Microsoft
Technology Roadmap
• Office 365 Implementation
• Hyper-V Optimizing
• Windows 8 Deployment
and much more!

Come See Paul Thurrott & Rod Trent in Person!

Early Registration Now Open

Upcoming Training

Mastering System Center 2012

During over 6 hours of training you can join John Savill from your computer as he will walk you through the key components and capabilities of System Center 2012, what’s involved in using the components, and the benefit they can bring to your environment.

Register Now

Current Issue

May 2013 - The NameTranslate object is useful when you need to translate Active Directory object names between different formats, but it's awkward to use from PowerShell. Here's a PowerShell script that eliminates the awkwardness.

CURRENT ISSUE / ARCHIVE / SUBSCRIBE

Windows Forums

Get answers to questions, share tips, and engage with the Windows Community in our Forums.