Skip to content

Instantly share code, notes, and snippets.

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
$Cleanup=Test-Path -Path "C:\HypervisorRestartLogs\*.txt"
if ($Cleanup -eq 'True') {
Remove-Item -Path C:\HypervisorRestartLogs\*.txt
}
# Creating Log files
New-Item C:\HypervisorRestartLogs -ItemType Directory -ErrorAction SilentlyContinue
New-Item C:\HypervisorRestartLogs\Logfiles.txt -ItemType File -ErrorAction SilentlyContinue
Get-Date | Out-File -FilePath C:\HypervisorRestartLogs\Logfiles.txt -Append