Command/More/CheckHyperV.ps1
Import-Module CmxModule -Force # This code enforces the "Elevate dialog" if the script has no been elevated yet. if (-not (IsElevated)) { $thisFile = $myinvocation.MyCommand.Definition Start-Process powershell.exe -Verb RunAs -ArgumentList "`"$thisFile`" $args" exit } # The following code is executed only when the user has answered the "Elevate dialog" with yes. $caption = (Get-CimInstance Win32_OperatingSystem).Caption Write-Host "Checking HyperV state of OS [$caption] . . . " if ($caption -match 'Microsoft Windows 10') { $state = (Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online).State Write-Output "Hyper-V state: $state" # if ($state -ne 'Enabled') # { # Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All # } } elseif ($caption -match 'Microsoft Windows Server') { $state = (Get-WindowsFeature -Name Hyper-V) Write-Output "Hyper-V state: $state" # if ($state -eq $false) # { # Install-WindowsFeature -Name Hyper-V -IncludeManagementTools # } } else { Write-Output "Hyper-V state: Unkown" } Read-Host "Exit script ? " |