Files
CKS-Lessons/lab-environment/01-enable-wsl.ps1
2026-08-27 11:50:09 +06:00

29 lines
1.1 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$principal = New-Object Security.Principal.WindowsPrincipal(
[Security.Principal.WindowsIdentity]::GetCurrent()
)
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
$arguments = @(
'-NoProfile',
'-ExecutionPolicy', 'Bypass',
'-File', ('"{0}"' -f $PSCommandPath)
)
Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList $arguments -Wait
exit $LASTEXITCODE
}
Write-Host 'Enabling Windows Subsystem for Linux...'
& dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
if ($LASTEXITCODE -notin 0, 3010) { throw "DISM failed with exit code $LASTEXITCODE" }
Write-Host 'Enabling Virtual Machine Platform...'
& dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
if ($LASTEXITCODE -notin 0, 3010) { throw "DISM failed with exit code $LASTEXITCODE" }
Write-Host ''
Write-Host 'Windows features are enabled. Restart Windows, then run:'
Write-Host ' .\02-install-and-build.ps1'