2023-10-31 12:20:46 +01:00
<#
2021-08-02 20:45:34 +02:00
. SYNOPSIS
2021-10-04 21:29:23 +02:00
Installs Windows Subsystem for Linux ( needs admin rights )
2021-08-02 20:45:34 +02:00
. DESCRIPTION
2022-01-29 12:47:46 +01:00
This PowerShell script installs Windows Subsystem for Linux . It needs admin rights .
2021-08-02 20:45:34 +02:00
. EXAMPLE
2023-08-06 21:35:36 +02:00
PS > . / install-wsl . ps1
2021-08-02 20:45:34 +02:00
. LINK
https : / / github . com / fleschutz / PowerShell
2022-01-29 12:47:46 +01:00
. NOTES
2022-09-06 21:42:04 +02:00
Author : Markus Fleschutz | License : CC0
2021-08-02 20:45:34 +02:00
#>
2021-09-11 11:37:22 +02:00
# Requires -RunAsAdministrator
2021-08-02 20:45:34 +02:00
try {
$StopWatch = [ system.diagnostics.stopwatch ] :: startNew ( )
if ( $false ) {
& wsl - -install
} else {
2021-09-19 19:09:33 +02:00
" 👉 Step 1/3: Enable WSL... "
2021-08-02 20:45:34 +02:00
& dism . exe / online / enable-feature / featurename : Microsoft-Windows -Subsystem -Linux / all / norestart
2021-09-19 19:09:33 +02:00
" 👉 Step 2/3: Enable virtual machine platform... "
2021-08-02 20:45:34 +02:00
& dism . exe / online / enable-feature / featurename : VirtualMachinePlatform / all / norestart
2021-09-19 19:09:33 +02:00
" 👉 Step 3/3: Enable WSL version 2... "
2021-08-02 20:45:34 +02:00
& wsl - -set -default -version 2
}
[ int ] $Elapsed = $StopWatch . Elapsed . TotalSeconds
" ✔️ installed Windows Subsystem for Linux (WSL) in $Elapsed sec "
" NOTE: reboot now, then visit the Microsoft Store and install a Linux distribution (e.g. Ubuntu, openSUSE, SUSE Linux, Kali Linux, Debian, Fedora, Pengwin, or Alpine) "
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-08-02 20:45:34 +02:00
} catch {
2022-04-13 12:06:32 +02:00
" ⚠️ Error in line $( $_ . InvocationInfo . ScriptLineNumber ) : $( $Error [ 0 ] ) "
2021-08-02 20:45:34 +02:00
exit 1
}