Script to Start All VMs on a Hyper-V Server? Need a script to start all the VMs on a server with the Hyper-V role enabled?<hr size="1" align="left" width="25%">Tony Soper© 2009 Microsoft Corporation. All rights reserved.Thu, 30 Oct 2008 19:22:02 Z4a399f3f-3f5f-4d67-bfae-55896d9e6570http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/4a399f3f-3f5f-4d67-bfae-55896d9e6570#4a399f3f-3f5f-4d67-bfae-55896d9e6570http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/4a399f3f-3f5f-4d67-bfae-55896d9e6570#4a399f3f-3f5f-4d67-bfae-55896d9e6570tonysohttp://social.technet.microsoft.com/Profile/en-US/?user=tonysoScript to Start All VMs on a Hyper-V Server? Need a script to start all the VMs on a server with the Hyper-V role enabled?<hr size="1" align="left" width="25%">Tony SoperThu, 30 Oct 2008 19:08:00 Z2008-10-30T19:08:00Zhttp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/4a399f3f-3f5f-4d67-bfae-55896d9e6570#cdca97a3-f85e-49cd-8b40-67e54af89378http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/4a399f3f-3f5f-4d67-bfae-55896d9e6570#cdca97a3-f85e-49cd-8b40-67e54af89378tonysohttp://social.technet.microsoft.com/Profile/en-US/?user=tonysoScript to Start All VMs on a Hyper-V Server?  <p>'               Script starts all VMs on a Hyper-V enabled server<br>'               Cobbled together by <a href="mailto:Johnkel@Microsoft.com">Johnkel@Microsoft.com</a><br>'<br>strComputer = &quot;.&quot; <br>Set objWMIService = GetObject(&quot;winmgmts:\\&quot; &amp; strComputer &amp; &quot;\root\virtualization&quot;) <br>Set vmcollecion = objWMIService.ExecQuery(&quot;SELECT * FROM Msvm_ComputerSystem&quot;,,48) </p> <p>Wscript.Echo VbCrLF <br>Wscript.Echo &quot;Name                     Description                        State &quot;<br>Wscript.Echo &quot;------------------------ ---------------------------------- -------------&quot;</p> <p>' loop through all instances in collection<br>For each vm in vmcollecion<br> ' decode system state, based on codes identified via trial and error<br> VMStateCode = vm.EnabledState<br> Select Case VMStateCode <br>         Case 2 VMState = &quot;Running&quot;<br>          Case 3      VMState = &quot;PowerOff&quot;<br>          Case 4      VMState = &quot;ShuttingDown&quot;<br>         Case 10    VMState = &quot;Reset&quot;<br>         Case 32768 VMState = &quot;Paused&quot;<br>         Case 32770 VMState = &quot;Starting&quot;<br>  Case 32771 VMState = &quot;SnapshotInProgress&quot;<br>         Case 32772 VMState = &quot;Migrating&quot;<br>         Case 32773 VMState = &quot;Saving&quot;<br>         Case 32774 VMState = &quot;Stopping&quot;<br>         Case 32776 VMState = &quot;Pausing&quot; <br>         Case 32777 VMState = &quot;Resuming&quot;<br>         Case 32769 VMState = &quot;Saved&quot;<br>  Case  Else  VMState = &quot;Unclassified (so far)&quot;<br> End Select</p> <p> ' print out VM info state<br> Wscript.Echo VbCrLF <br> Wscript.Echo  vm.ElementName &amp; Space(25 - Len(vm.ElementName)) &amp; _<br>    vm.Description &amp; Space(35 - Len(vm.Description)) &amp; _ <br>   VMState &amp; &quot; (&quot; &amp; VMStateCode &amp; &quot;)&quot;</p> <p> ' request state change if appropriate - the host should never be eligible<br> if VMState &lt;&gt; &quot;Running&quot; and vm.Description &lt;&gt; &quot;Microsoft Hosting Computer System&quot; Then<br>  Wscript.Echo Space(25) &amp; &quot;Starting &quot; &amp; vm.ElementName</p> <p>  RequestReturn = vm.RequestStateChange(2)</p> <p>  if RequestReturn = 4096 Then<br>   Wscript.Echo Space(25) &amp; &quot;Start request submitted&quot;<br>  Else<br>   Wscript.Echo Space(25) &amp; &quot;Something goofy happened (&quot; &amp; RequestReturn &amp; &quot;)&quot;<br>  End If<br> End If<br>Next<br>Wscript.Echo VbCrLF </p> <p><br> </p><hr size="1" align="left" width="25%">Tony SoperThu, 30 Oct 2008 19:08:17 Z2008-10-30T19:08:17Zhttp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/4a399f3f-3f5f-4d67-bfae-55896d9e6570#c7fe82ed-9672-4f3c-9185-7b23e6984f9bhttp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/4a399f3f-3f5f-4d67-bfae-55896d9e6570#c7fe82ed-9672-4f3c-9185-7b23e6984f9btonysohttp://social.technet.microsoft.com/Profile/en-US/?user=tonysoScript to Start All VMs on a Hyper-V Server?  <p>'               Script starts all VMs on a Hyper-V enabled server<br>'               Cobbled together by <a href="mailto:Johnkel@Microsoft.com">Johnkel@Microsoft.com</a><br>'<br>strComputer = &quot;.&quot; <br>Set objWMIService = GetObject(&quot;winmgmts:\\&quot; &amp; strComputer &amp; &quot;\root\virtualization&quot;) <br>Set vmcollecion = objWMIService.ExecQuery(&quot;SELECT * FROM Msvm_ComputerSystem&quot;,,48) </p> <p>Wscript.Echo VbCrLF <br>Wscript.Echo &quot;Name                     Description                        State &quot;<br>Wscript.Echo &quot;------------------------ ---------------------------------- -------------&quot;</p> <p>' loop through all instances in collection<br>For each vm in vmcollecion<br> ' decode system state, based on codes identified via trial and error<br> VMStateCode = vm.EnabledState<br> Select Case VMStateCode <br>         Case 2 VMState = &quot;Running&quot;<br>          Case 3      VMState = &quot;PowerOff&quot;<br>          Case 4      VMState = &quot;ShuttingDown&quot;<br>         Case 10    VMState = &quot;Reset&quot;<br>         Case 32768 VMState = &quot;Paused&quot;<br>         Case 32770 VMState = &quot;Starting&quot;<br>  Case 32771 VMState = &quot;SnapshotInProgress&quot;<br>         Case 32772 VMState = &quot;Migrating&quot;<br>         Case 32773 VMState = &quot;Saving&quot;<br>         Case 32774 VMState = &quot;Stopping&quot;<br>         Case 32776 VMState = &quot;Pausing&quot; <br>         Case 32777 VMState = &quot;Resuming&quot;<br>         Case 32769 VMState = &quot;Saved&quot;<br>  Case  Else  VMState = &quot;Unclassified (so far)&quot;<br> End Select</p> <p> ' print out VM info state<br> Wscript.Echo VbCrLF <br> Wscript.Echo  vm.ElementName &amp; Space(25 - Len(vm.ElementName)) &amp; _<br>    vm.Description &amp; Space(35 - Len(vm.Description)) &amp; _ <br>   VMState &amp; &quot; (&quot; &amp; VMStateCode &amp; &quot;)&quot;</p> <p> ' request state change if appropriate - the host should never be eligible<br> if VMState &lt;&gt; &quot;Running&quot; and vm.Description &lt;&gt; &quot;Microsoft Hosting Computer System&quot; Then<br>  Wscript.Echo Space(25) &amp; &quot;Starting &quot; &amp; vm.ElementName</p> <p>  RequestReturn = vm.RequestStateChange(2)</p> <p>  if RequestReturn = 4096 Then<br>   Wscript.Echo Space(25) &amp; &quot;Start request submitted&quot;<br>  Else<br>   Wscript.Echo Space(25) &amp; &quot;Something goofy happened (&quot; &amp; RequestReturn &amp; &quot;)&quot;<br>  End If<br> End If<br>Next<br>Wscript.Echo VbCrLF </p> <p><br> </p><hr size="1" align="left" width="25%">Tony SoperThu, 30 Oct 2008 19:11:49 Z2008-10-30T19:11:49Z