Script to Pause all Hyper-V VMs?Need a script to pause 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:25:06 Zef604379-1802-44fd-a01d-31c0ca1aba16http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/ef604379-1802-44fd-a01d-31c0ca1aba16#ef604379-1802-44fd-a01d-31c0ca1aba16http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/ef604379-1802-44fd-a01d-31c0ca1aba16#ef604379-1802-44fd-a01d-31c0ca1aba16tonysoperhttp://social.technet.microsoft.com/Profile/en-US/?user=tonysoperScript to Pause all Hyper-V VMs?Need a script to pause 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:24:47 Z2008-10-30T19:24:47Zhttp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/ef604379-1802-44fd-a01d-31c0ca1aba16#fea4d657-42f6-450b-8642-51fa1d9d901dhttp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/ef604379-1802-44fd-a01d-31c0ca1aba16#fea4d657-42f6-450b-8642-51fa1d9d901dtonysoperhttp://social.technet.microsoft.com/Profile/en-US/?user=tonysoperScript to Pause all Hyper-V VMs?<p>'               Script pauses all VMs on a Hyper-V enabled server<br>'               Cobbled together by <a href="mailto:Johnkel@Microsoft.com">Johnkel@Microsoft.com</a><br>'<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;Saved&quot; and VMState &lt;&gt; &quot;Off&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(32768)</p> <p>  if RequestReturn = 4096 Then<br>   Wscript.Echo Space(25) &amp; &quot;Pause 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 <br></p><hr size="1" align="left" width="25%">tony soperThu, 30 Oct 2008 19:25:02 Z2008-10-30T19:25:02Z