Files
management-scripts/Enable-HyperVFeatures.ps1
2024-09-19 15:05:29 -04:00

18 lines
941 B
PowerShell

# Exit if the endpoint is a server edition
Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property ProductType | ForEach-Object { If ( $_.ProductType -gt 1 ) { Return } }
# Exit if the endpoint is not running at least Windows 10
If ( IsWindowsVersion -lt "10.0" ) { Return }
# Exit if the endpoint is not running the Pro/Enterprise version of Windows
$Edition = ($(systeminfo | findstr /B /C:"OS Name") -replace "OS Name:","").Trim()
If ( ($Edition -notmatch "Pro") -and ($Edition -notmatch "Enterprise") ) { Return }
# Exit if Hyper-V is already enabled
If ( (Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V).State -eq "Enabled" ) { Return }
# Endpoint is running the correct version of Windows, enabling Hyper-V features
Write-Output "Enabling Hyper-V features"
Try { Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart }
Catch { Write-Error $_.Exception.Message }