0

I would like to ask how to find all VM/Hyper-V on Window Server 2012 with the use of power-shell and then restart/reboot them with the use of power-shell script?

The next thing is: I cannot even find any get command for it: enter image description here

================== Added in 2014-08-15 have find a reference link that help me a lot, just share here http://technet.microsoft.com/en-us/library/hh848479.aspx

Question-er XDD
  • 640
  • 3
  • 12
  • 27
  • Have you looked in the [Hyper-V module](http://technet.microsoft.com/en-us/library/hh848559.aspx)? `Get-Command -Module Hyper-V` – Mike Zboray Jul 22 '14 at 08:18
  • Yes I have tried it, seems no result is outputted. However, my Hyper-V Manager can show the VM info such as status,CPU Usage etc – Question-er XDD Jul 22 '14 at 09:22

1 Answers1

1

Run Powershell elevated (!) and execute following:

ForEach ($VM in Hyper-V\Get-VM | Where {$_.State -ne "Off") {
        Restart-Computer -ComputerName $VM.Name
}

Non-elevated Powershell will not return any results.

Martin

Martin Zugec
  • 165
  • 1
  • 7
  • thanks,I have tried it out for nearly a month. And your solution is possible, just wanna know when to use { and when to use (, is the concept just like C program? – Question-er XDD Aug 15 '14 at 00:54