Skip to content

Instantly share code, notes, and snippets.

@BorysVrublevskyi
Last active February 1, 2023 19:46
Show Gist options
  • Save BorysVrublevskyi/170e42d16513e3d49e1f502800917ed5 to your computer and use it in GitHub Desktop.
Save BorysVrublevskyi/170e42d16513e3d49e1f502800917ed5 to your computer and use it in GitHub Desktop.
Some handy Hyper-V commands for PowerShell
# 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