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

A simple PowerShell command does the job.

John Savill

November 4, 2011

2 Min Read
ITPro Today logo in a gray background | ITPro Today

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 switch. Here's an example of how such a command looks:

Import-Module "c:Program FilesmodulesHyperVHyperv.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 0

When 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

About the Author

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