Q: How can I change the automatic start state of a virtual machine by using Windows PowerShell?

A: Try the Windows PowerShell cmdlets for Hyper-V. In my FAQ "Q: Are there PowerShell cmdlets for Hyper-V?" I introduced the Hyper-V PowerShell cmdlets, which let you perform most Hyper-V actions and configurations from within PowerShell.

Also within PowerShell, you have the ability to set the automatic start setting for virtual machines (VMs). This controls what the VM does when the system starts: never auto start, auto start if it was running when the system stopped, or always auto start. You enter a numeric value in the command that designates the auto-start configuration:

  0: Never auto start
  1: Restart if previously running when service stopped
  2: Always start automatically

Then you pass the name of the VM with the -autostart <value> switch. Here's an example of how such a command looks:

Import-Module "c:\Program Files\modules\HyperV\Hyperv.psd1"
set-vm savdaldpm01 -autostart 0

You can also take it a step further. Say, for example, that you want to set all VMs to never auto start. You can just pipe the output of get-vm (which lists all VMs on the current box) to the set-vm cmdlet:

PS C:\> get-vm | set-vm -autostart 0When I entered it for my setup, it returned the output below:

Modified VM Global Settings object for Win8TestDevPrev
Modified VM Global Settings object for savdalthinpc
Modified VM Global Settings object for savdalync01
Modified VM Global Settings object for savdalclient.savilltech.net
Modified VM Global Settings object for savdalcm01
Modified VM Global Settings object for savloncli01
Modified VM Global Settings object for savdalclient2.savilltech.net
Modified VM Global Settings object for hypervserv
Modified VM Global Settings object for savdalvmm12
Modified VM Global Settings object for savdalfs01
Modified VM Global Settings object for APPVSequence
Modified VM Global Settings object for savdalfim01
Modified VM Global Settings object for savdalappv01
Modified VM Global Settings object for PXETest
Modified VM Global Settings object for savdalts01
Modified VM Global Settings object for savdalex10
Modified VM Global Settings object for savdalrodc01
Modified VM Global Settings object for savdalclient3.savilltech.net
Modified VM Global Settings object for savdaldc10
Modified VM Global Settings object for suseentdesk
Modified VM Global Settings object for Win8TestDevPrev2
Modified VM Global Settings object for savloncli02
Modified VM Global Settings object for savdalclient4.savilltech.net
Modified VM Global Settings object for Win8TestClient
Modified VM Global Settings object for savdaldc11
Modified VM Global Settings object for savdalsmdw01
Modified VM Global Settings object for savdalwss10
Modified VM Global Settings object for savdalcb01
Modified VM Global Settings object for savdalom01
Modified VM Global Settings object for savdalsm01
Modified VM Global Settings object for test
Modified VM Global Settings object for savdaldpm01

Please or Register to post comments.

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.