How do I configure a Timed restart for Multiple Hyper-V VMs on Server 2012?
How do I script a timed restarting of multiple VMs on Hyper-v 2012 Server. I have tested the restart process and found it needs to run in PowerShell running as administrator. I have tried to run a simple shutdown -r -f, and having task scheduler keep time. Help please.
Microsoft Legacy OSHyper-V
Last Comment
technologyone
8/22/2022 - Mon
McKnife
The restart can be done from inside the machines (task scheduler on each machine or task scheduler on one machine that does shutdown remote machines ->look at the options of shutdown.exe /?), or it can be done through the host - yes, powershell.
please articulate what problems you are seeing, it's very simple.
technologyone
ASKER
I would like to run this from the host if possible. I have about 50 VMs and want easy modification for the future. I am having trouble scripting the Restart-VM in PowerShell to run as administrator. I know I am not doing something, but I am relatively new to scripting.
McKnife
What trouble do you have?
The restart-vm has examples in its help, did you read those?
The vmhost could start a simple restart.ps1 script though task scheduler using system rights (the system account would be the executioner).
This only works as long as it is directly in the task scheduler arguments section. If I put this script in a restart.ps1 file and insert this in the filed it errors out and I cant read the error before it is gone.
technologyone
ASKER
Ok I have inserted the " get-vm |restart-vm -force " on the Task Scheduler arguments line and it seems to be working. I will try it in production tonight. Thanks for the suggestion.
Turn on this policy: computer config - policies - adm. templates - Windows Components/Windows PowerShell - Execution Policy: Allow local scripts and remote signed scripts
technologyone
ASKER
I will post tomorrow to close question after in production solution has run. Thank you again for the assistance.
please articulate what problems you are seeing, it's very simple.