By using this site, you agree to the Privacy Policy.
Accept
EnterinITEnterinITEnterinIT
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
    • Azure
    • ConfigMgr/SCCM
    • DPM
    • Orchestrator
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Office 365
    • Office Insider
    • Power BI
    • Skype
    • SQL Server
    • Teams
  • WINDOWS
    • Windows Admin Center
    • Windows Client
    • Windows Server
  • SCCM Query Collection List
Reading: Hyper-V Virual Machine Restart PowerShell Script
Font ResizerAa
EnterinITEnterinIT
Font ResizerAa
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
  • WINDOWS
  • SCCM Query Collection List
Search
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
    • Azure
    • ConfigMgr/SCCM
    • DPM
    • Orchestrator
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Office 365
    • Office Insider
    • Power BI
    • Skype
    • SQL Server
    • Teams
  • WINDOWS
    • Windows Admin Center
    • Windows Client
    • Windows Server
  • SCCM Query Collection List
Hyper-V

Hyper-V Virual Machine Restart PowerShell Script

Published February 11, 2024
1 Min Read
SHARE

Hyper-V Virtual Machine Restart PowerShell Script. In our company, we use VDI infrastructure with virtual machine pools working at Windows Server Hyper-V 2012 R2. Because we have many GPO, that fast changed and applied to the workstation we need to reboot machines occasionally. But not used machines went to save state if not using about 10 minutes. So we decide to write this script to “reboot machines” at night and create a task in the windows scheduler. As we have 4 pools we create 4 scripts for pools VMs and 4 tasks, that run at night with intervals of 2 hours.

How to:

Because we save not used machines we can’t reboot them, so we do run – shutdown – run – save. Maybe it’s somewhere wrong, but it’s work. This is the Windows PowerShell script:

$VMs = Get-VM 21V-PUBL01-*
Foreach ($VM in $VMs)
{
Start-VM $vm
timeout 60
Stop-VM $vm -passthru
timeout 60
Start-VM $vm
timeout 60
Save-VM $vm
}
TAGGED:Microsoft Hyper-VMicrosoft Windows ServerPowerShell
Previous Article Install SQL Server 2016 for Configuration Manager
Next Article Sidder: Quickly see which User Profile Disk maps to which Domain User
Leave a Comment Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Translation

English中文(简体)DanskNederlandsFrançaisDeutschItaliano한국어PolskiPortuguêsRomânăEspañolУкраїнська
by Transposh - translation plugin for wordpress

Popular Posts

System Requirements for Windows Server 2016
Windows Server
Configuration Manager Query Collection List
Configuration Manager Query Collection List
ConfigMgr
Structured/Managed Navigation enabled on Modern Pages in Classic Team Sites
Tech
SCCM Failed to get DP locations as the expected version from MP
ConfigMgr

Recent Posts

Installing and Configuring Fail2ban for SSH Protection on Ubuntu 24.04
Linux
Enabling and Configuring FirewallD on AlmaLinux
Linux
User Creation and SSH Key Setup in AlmaLinux
Linux
How to reset password on AlmaLinux
Linux

© 2023 EnterinIT

Go to mobile version
adbanner
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?