Script Center > Scripting Forums > The Official Scripting Guys Forum! > Script to Turn Off all Hyper-V VMs?
Ask a questionAsk a question
 

AnswerScript to Turn Off all Hyper-V VMs?

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

Answers

  • Thursday, October 30, 2008 7:04 PMtonyso Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    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 bytonyso Thursday, October 30, 2008 7:04 PMhas code
    • Marked As Answer bytonyso Thursday, October 30, 2008 7:04 PM
    •  

All Replies

  • Thursday, October 30, 2008 7:04 PMtonyso Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    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 bytonyso Thursday, October 30, 2008 7:04 PMhas code
    • Marked As Answer bytonyso Thursday, October 30, 2008 7:04 PM
    •  
  • Monday, November 24, 2008 1:26 PMDungKHoang Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
     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