none
Script to Turn Off all Hyper-V VMs?

    Question

  • Need a script to Turn Off all the VMs running on a server with the Hyper-V role enabled?
    Tony Soper
    Thursday, October 30, 2008 7:02 PM

Answers

  • John Kelbley provides one, you can leave feedback here or contact johnkel@microsoft.com:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\virtualization")
    Set vmcollecion = objWMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem",,48)

    ' loop through all instances in collection
    For each vm in vmcollecion
     RequestReturn = vm.RequestStateChange(3)
    Next



    Tony Soper
    • Edited by tonyso Thursday, October 30, 2008 7:04 PM has code
    • Marked as answer by tonyso Thursday, October 30, 2008 7:04 PM
    Thursday, October 30, 2008 7:04 PM

All replies

  • John Kelbley provides one, you can leave feedback here or contact johnkel@microsoft.com:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\virtualization")
    Set vmcollecion = objWMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem",,48)

    ' loop through all instances in collection
    For each vm in vmcollecion
     RequestReturn = vm.RequestStateChange(3)
    Next



    Tony Soper
    • Edited by tonyso Thursday, October 30, 2008 7:04 PM has code
    • Marked as answer by tonyso Thursday, October 30, 2008 7:04 PM
    Thursday, October 30, 2008 7:04 PM
  •  You can also check my blog on Hyper-V  and PowerShell.
    I have some examples using PowerShell coding against WMI

    EnjoY!
    /Dung

    http://dungkhoang.spaces.live.com

    Monday, November 24, 2008 1:26 PM