Created
January 27, 2012 15:06
-
-
Save mhinze/1689202 to your computer and use it in GitHub Desktop.
rebootin vms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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