Last active
September 19, 2017 12:52
-
-
Save rdrake/2cbc40a71d5aec006bee88c2cfa31b56 to your computer and use it in GitHub Desktop.
Configures developer mode and installs WSL feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -RunAsAdministrator | |
<# | |
.SYNOPSIS | |
Enable Windows Subsystem for Linux (Ubuntu) on Windows 10 version 1607 or later. | |
.DESCRIPTION | |
This script will configure Developer Mode in order to enable Windows Subsystem for Linux (Ubuntu) on Windows 10 version 1607 or later. | |
.EXAMPLE | |
Prepare Windows 10 for Windows Subsystem for linux and install required features: | |
.\Enable-UbuntuForWindows.ps1 | |
powershell -nop -c "iex(New-Object Net.WebClient).DownloadString('https://goo.gl/dDX8GR')" | |
.NOTES | |
FileName: Enable-UbuntuForWindows.ps1 | |
Maintainer: Richard Drake <richard.drake@uoit.ca> | |
Original Author: Nickolaj Andersen (@NickolajA) | |
Created: 2016-09-08 | |
Updated: 2017-09-19 | |
Version history: | |
1.0.0 - (2016-09-08) Script created | |
1.1.0 - (2017-09-19) Script cleaned up and modified to support non-SCCM deployment | |
#> | |
# https://stackoverflow.com/questions/37352912/how-to-return-true-false-to-get-windowsoptionalfeature-on-windows-10 | |
function Check-WindowsFeature { | |
[CmdletBinding()] | |
param( | |
[Parameter(Position=0,Mandatory=$true)] [string]$FeatureName | |
) | |
if((Get-WindowsOptionalFeature -FeatureName $FeatureName -Online).State -eq "Enabled") { | |
Write-Warning -Message "$FeatureName already enabled" | |
} else { | |
# Enable required Windows Features for Linux Subsystem | |
try { | |
Enable-WindowsOptionalFeature -FeatureName $FeatureName -Online -All -LimitAccess -ErrorAction Stop | |
} | |
catch [System.Exception] { | |
Write-Error -Message "An error occured when enabling Microsoft-Windows-Subsystem-Linux feature, see DISM log for more information" | |
} | |
} | |
} | |
# Validate Windows 10 version 1607 build | |
if ([int](Get-WmiObject -Class Win32_OperatingSystem).BuildNumber -lt 14393) { | |
Write-Error -Message "Unsupported build of Windows 10 detected, exiting" ; exit 1 | |
} | |
# Create AppModelUnlock if it doesn't exist, required for enabling Developer Mode | |
$RegistryKeyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" | |
if (-not(Test-Path -Path $RegistryKeyPath)) { | |
New-Item -Path $RegistryKeyPath -ItemType Directory -Force | |
} | |
# Add registry value to enable Developer Mode | |
New-ItemProperty -Path $RegistryKeyPath -Name AllowDevelopmentWithoutDevLicense -PropertyType DWORD -Value 1 -Force | Out-Null | |
Check-WindowsFeature Microsoft-Windows-Subsystem-Linux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment