Skip to content

Instantly share code, notes, and snippets.

@Vibhu2
Created October 6, 2022 19:16
Show Gist options
  • Save Vibhu2/18ce914d63bbbd06c65c1b512160ef0d to your computer and use it in GitHub Desktop.
Save Vibhu2/18ce914d63bbbd06c65c1b512160ef0d to your computer and use it in GitHub Desktop.
Checking for auto start on VMS
$AutostartStatus= Get-VM | Select-Object VMname,AutomaticStartAction,AutomaticStartDelay,AutomaticStopAction
#$AutostartStatus | where-Object { ($_.AutomaticStartAction -ine 'Start') -or ($_.AutomaticStartAction -ine 'StartIfRunning')}
$vmstostart= $AutostartStatus | where-Object { ($_.AutomaticStartAction -eq 'Nothing')}
# starting Back Virtul Machines
Write-verbose "Getting status of VM's from the log file"
$InetiallyRunningMachines= Get-Content -Path C:\HypervisorRestartLogs\RunningMachines.txt
Get-Date | Out-File -FilePath C:\HypervisorRestartLogs\Logfiles.txt -Append
#$InetiallyRunningMachines| Where-Object { $_.State -eq 'Saved' } | Start-VM
$InetiallyRunningMachines | Select-Object VMname,AutomaticStartAction,AutomaticStartDelay,AutomaticStopAction
$vmstostart= $AutostartStatus | where-Object { ($_.AutomaticStartAction -eq 'Nothing')}
$vmstostart.VMname | Start-VM
# $InetiallyRunningMachines | Start-VM
# Logging Virtual Machines State
$MachinesState = Get-VM
$MachinesState | Out-File -FilePath C:\HypervisorRestartLogs\Logfiles.txt -Append
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment