Last active
February 1, 2023 19:46
-
-
Save BorysVrublevskyi/170e42d16513e3d49e1f502800917ed5 to your computer and use it in GitHub Desktop.
Some handy Hyper-V commands for PowerShell
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
# Get info | |
Get-VM -VMname * | Select-Object VMname,State,AutomaticStartAction #,AutomaticStartDelay,AutomaticStopAction | |
# Start all VMs that must be running | |
Get-VM -VMname * | Select-Object VMname,State,AutomaticStartAction | ` | |
Where-Object {($_.State -eq 'Off') -and ($_.AutomaticStartAction -eq 'Start')} | ` | |
select -ExpandProperty VMname | Start-VM | |
# Turn off critical VMs | |
Get-VM -VMname * | Select-Object VMname,State,AutomaticStartAction | ` | |
Where-Object {($_.State -eq 'RunningCritical') -and ($_.AutomaticStartAction -eq 'Start')} | ` | |
select -ExpandProperty VMname | Stop-VM -TurnOff | |
# Turn off all VMs | |
Get-VM -VMname * | Select-Object VMname,State,AutomaticStartAction | ` | |
Where-Object {($_.State -eq 'Running') -and ($_.AutomaticStartAction -eq 'Start')} | ` | |
select -ExpandProperty VMname | Stop-VM -TurnOff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment