Schedule VMs in VDI pool to reboot by powershell and windows scheduler
In our company we has VDI infrastrucure with virtual machines pools working at Windows Server Hyper-V 2012 R2. Because we has many GPO, that fast changed, applied to workstation we need to reboot machines occasionally. But not used machines went to save state if not using about 10 minutes. So we decide write this script to "reboot machines" at night and create a task in windows scheduler. As we has 4 pools we create 4 scripts for pools VMs and 4 tasks, that run at night with interval 2 hours.
Because we save not used machines we can't reboot they, so we do run - shutdown - run - save. Maybe it's somewhere wrong, but it's work . This is the script:
$VMs = Get-VM 21V-PUBL01-*
Foreach ($VM in $VMs)
Stop-VM $vm -passthru