Skip to content

Instantly share code, notes, and snippets.

@mhinze
Created January 27, 2012 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhinze/1689202 to your computer and use it in GitHub Desktop.
Save mhinze/1689202 to your computer and use it in GitHub Desktop.
rebootin vms
while($true){
$query = "SELECT * FROM Msvm_ComputerSystem "
$VM = get-wmiobject -query $query -namespace "root\virtualization" -computername "."
$vmToRestart = $vm | where-object { $_.ElementName -ne "YOUR HOSTNAME"} |sort TimeOfLastStateChange | select-object -Index 0
$vmToRestart
$vmToRestart.RequestStateChange(3)
start-sleep -seconds 120
$vmToRestart.RequestStateChange(2)
start-sleep -Seconds 300
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment