diff --git a/dev_app.ps1 b/dev_app.ps1 index 3a5e7c22..aeb0c7e9 100644 --- a/dev_app.ps1 +++ b/dev_app.ps1 @@ -21,6 +21,8 @@ function executeScript { iex ((new-object net.webclient).DownloadString("$helperUri/$script")) } +executeScript "CompatibilityChecks.ps1"; + #--- Setting up Windows --- executeScript "SystemConfiguration.ps1"; executeScript "FileExplorerSettings.ps1"; diff --git a/dev_app_desktop_.NET.ps1 b/dev_app_desktop_.NET.ps1 index cb8c4e60..7e11829c 100644 --- a/dev_app_desktop_.NET.ps1 +++ b/dev_app_desktop_.NET.ps1 @@ -21,6 +21,8 @@ function executeScript { iex ((new-object net.webclient).DownloadString("$helperUri/$script")) } +executeScript "CompatibilityChecks.ps1"; + #--- Setting up Windows --- executeScript "SystemConfiguration.ps1"; executeScript "FileExplorerSettings.ps1"; diff --git a/dev_app_desktop_cplusplus.ps1 b/dev_app_desktop_cplusplus.ps1 index e0669d4c..d173b1e8 100644 --- a/dev_app_desktop_cplusplus.ps1 +++ b/dev_app_desktop_cplusplus.ps1 @@ -21,6 +21,8 @@ function executeScript { iex ((new-object net.webclient).DownloadString("$helperUri/$script")) } +executeScript "CompatibilityChecks.ps1"; + #--- Setting up Windows --- executeScript "SystemConfiguration.ps1"; executeScript "FileExplorerSettings.ps1"; diff --git a/dev_ml_windows.ps1 b/dev_ml_windows.ps1 index 32997d5d..a36cbd66 100644 --- a/dev_ml_windows.ps1 +++ b/dev_ml_windows.ps1 @@ -21,6 +21,8 @@ function executeScript { iex ((new-object net.webclient).DownloadString("$helperUri/$script")) } +executeScript "CompatibilityChecks.ps1"; + #--- Setting up Windows --- executeScript "SystemConfiguration.ps1"; executeScript "FileExplorerSettings.ps1"; diff --git a/dev_ml_wsl.ps1 b/dev_ml_wsl.ps1 index b744dd3d..1676bdfb 100644 --- a/dev_ml_wsl.ps1 +++ b/dev_ml_wsl.ps1 @@ -21,6 +21,8 @@ function executeScript { iex ((new-object net.webclient).DownloadString("$helperUri/$script")) } +executeScript "CompatibilityChecks.ps1"; + #--- Setting up Windows --- executeScript "SystemConfiguration.ps1"; executeScript "FileExplorerSettings.ps1"; diff --git a/dev_web.ps1 b/dev_web.ps1 index 2d001c5a..d9a82b10 100644 --- a/dev_web.ps1 +++ b/dev_web.ps1 @@ -21,6 +21,8 @@ function executeScript { iex ((new-object net.webclient).DownloadString("$helperUri/$script")) } +executeScript "CompatibilityChecks.ps1"; + #--- Setting up Windows --- executeScript "FileExplorerSettings.ps1"; executeScript "SystemConfiguration.ps1"; diff --git a/dev_web_nodejs.ps1 b/dev_web_nodejs.ps1 index 55ba0be2..b336eb01 100644 --- a/dev_web_nodejs.ps1 +++ b/dev_web_nodejs.ps1 @@ -21,6 +21,8 @@ function executeScript { iex ((new-object net.webclient).DownloadString("$helperUri/$script")) } +executeScript "CompatibilityChecks.ps1"; + #--- Setting up Windows --- executeScript "SystemConfiguration.ps1"; executeScript "FileExplorerSettings.ps1"; diff --git a/devops_azure.ps1 b/devops_azure.ps1 index 2ea6071c..c8649581 100644 --- a/devops_azure.ps1 +++ b/devops_azure.ps1 @@ -22,6 +22,8 @@ function executeScript { iex ((new-object net.webclient).DownloadString("$helperUri/$script")) } +executeScript "CompatibilityChecks.ps1"; + #--- Setting up Windows --- executeScript "FileExplorerSettings.ps1"; executeScript "SystemConfiguration.ps1"; diff --git a/scripts/CompatibilityChecks.ps1 b/scripts/CompatibilityChecks.ps1 new file mode 100644 index 00000000..639f4f36 --- /dev/null +++ b/scripts/CompatibilityChecks.ps1 @@ -0,0 +1,78 @@ +# Helper functions for compatibility checks + +# Returns $true if running a 64-bit OS. +# TODO: checks for non-x86-based architectures, eg. ARM64 +function Is-64Bit +{ + return [Environment]::Is64BitOperatingSystem +} + +# Returns $true if running on a server edition of Windows. +function Is-Server +{ + return ((Get-WmiObject Win32_OperatingSystem).ProductType -gt 1) +} + +# Returns $true if system has hardware virtualization enabled. +function Is-Virtualization-Capable +{ + return (Get-WmiObject Win32_Processor).VirtualizationFirmwareEnabled +} + +# Returns $true if system should be capable of Hyper-V virtualization. +function Is-HyperV-Capable +{ + # Ensure we're running on a 64-bit operating system + if(-Not (Is-64Bit)) { + return $false + } + + # Ensure hardware virtualization is available and enabled + if(-Not (Is-Virtualization-Capable)) { + return $false + } + + # Ensure product SKU supports Hyper-V + # Source for SKU IDs: https://docs.microsoft.com/en-gb/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getproductinfo + if((Get-WmiObject Win32_OperatingSystem).OperatingSystemSKU -NotIn 0x06, 0x10, 0x12, 0x50, 0x8, 0xC, 0x79, 0x7A, 0x04, 0x46, 0x48, 0x1B, 0x54, 0x7D, 0x81, 0x7E, 0x82, 0x0A, 0x0E, 0x2A, 0xA1, 0xA2, 0x30, 0x45, 0x31, 0x67, 0x18, 0x4F, 0x07, 0x0D, 0x01, 0x47, 0x1C) + { + return $false + } + + $BuildVersion = [System.Environment]::OSVersion.Version + + # Ensure that we're not running on XP + if($BuildVersion.Major -lt '6') + { + return $false + } + + # Windows Server 2008/R2 and variants + if($BuildVersion.Major -eq '6' -and $BuildVersion.Minor -lt '2') + { + # Ensure we aren't running on a client edition + if(-Not (Is-Server)) { + return $false + } + + return $true + } + + # Windows 8/8.1 and Windows Server 2012/R2 + if($BuildVersion.Major -ge '6' -and $BuildVersion.Minor -ge '2') + { + # Client Hyper-V requires SLAT + if(-Not (Is-Server)) { + return (Get-WmiObject Win32_Processor).SecondLevelAddressTranslationExtensions + } + + return $true + } + + # Windows 10 / Windows Server 2016 and later + if($BuildVersion.Major -ge '10') + { + # Ensure SLAT is supported + return (Get-WmiObject Win32_Processor).SecondLevelAddressTranslationExtensions + } +} \ No newline at end of file diff --git a/scripts/Docker.ps1 b/scripts/Docker.ps1 index c2e7bbdd..e97b067d 100644 --- a/scripts/Docker.ps1 +++ b/scripts/Docker.ps1 @@ -1,4 +1,9 @@ -Enable-WindowsOptionalFeature -Online -FeatureName containers -All -RefreshEnv -choco install -y docker-for-windows -choco install -y vscode-docker +if( + (Is-HyperV-Capable) -and + # Windows 10 Anniversary Update or later + ((Get-WmiObject Win32_OperatingSystem).BuildNumber -ge 14393)) { + Enable-WindowsOptionalFeature -Online -FeatureName containers -All + RefreshEnv + choco install -y docker-for-windows + choco install -y vscode-docker +} diff --git a/scripts/HyperV.ps1 b/scripts/HyperV.ps1 index 1350cd37..98634716 100644 --- a/scripts/HyperV.ps1 +++ b/scripts/HyperV.ps1 @@ -1 +1,4 @@ -choco install -y Microsoft-Hyper-V-All --source="'windowsFeatures'" +# Install Hyper-V +if(Is-HyperV-Capable) { + choco install -y Microsoft-Hyper-V-All --source="'windowsFeatures'" +} \ No newline at end of file diff --git a/scripts/RemoveDefaultApps.ps1 b/scripts/RemoveDefaultApps.ps1 index c24a0734..35f68ab3 100644 --- a/scripts/RemoveDefaultApps.ps1 +++ b/scripts/RemoveDefaultApps.ps1 @@ -59,6 +59,9 @@ $applicationList = @( "*.AdobePhotoshopExpress" ); -foreach ($app in $applicationList) { - removeApp $app -} \ No newline at end of file +# If on Windows 8 / Server 2012 or later... +if([Environment]::OSVersion.Version -ge (New-Object 'Version' 6,2)) { + foreach ($app in $applicationList) { + removeApp $app + } +} diff --git a/scripts/SystemConfiguration.ps1 b/scripts/SystemConfiguration.ps1 index e70b2dda..cac0412d 100644 --- a/scripts/SystemConfiguration.ps1 +++ b/scripts/SystemConfiguration.ps1 @@ -1,4 +1,5 @@ - - #--- Enable developer mode on the system --- -Set-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\AppModelUnlock -Name AllowDevelopmentWithoutDevLicense -Value 1 +# (if on Windows 8 / Server 2012 or later) +if([Environment]::OSVersion.Version -ge (New-Object 'Version' 6,2)) { + Set-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\AppModelUnlock -Name AllowDevelopmentWithoutDevLicense -Value 1 +} \ No newline at end of file diff --git a/scripts/WSL.ps1 b/scripts/WSL.ps1 index fbf87b9b..0af3503a 100644 --- a/scripts/WSL.ps1 +++ b/scripts/WSL.ps1 @@ -1,30 +1,39 @@ -choco install -y Microsoft-Windows-Subsystem-Linux --source="'windowsfeatures'" +if ( + (Is-64Bit) -and ( + ( + ( + (-Not (Is-Server)) -and (Get-WmiObject Win32_OperatingSystem).BuildNumber -ge 14316 + ) -or + (Get-WmiObject Win32_OperatingSystem).BuildNumber -ge 16299 + ) + ) { + choco install -y Microsoft-Windows-Subsystem-Linux --source="'windowsfeatures'" -#--- Ubuntu --- -# TODO: Move this to choco install once --root is included in that package -Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu.appx -UseBasicParsing -Add-AppxPackage -Path ~/Ubuntu.appx -# run the distro once and have it install locally with root user, unset password + #--- Ubuntu --- + # TODO: Move this to choco install once --root is included in that package + Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu.appx -UseBasicParsing + Add-AppxPackage -Path ~/Ubuntu.appx + # run the distro once and have it install locally with root user, unset password -RefreshEnv -Ubuntu1804 install --root -Ubuntu1804 run apt update -Ubuntu1804 run apt upgrade -y + RefreshEnv + Ubuntu1804 install --root + Ubuntu1804 run apt update + Ubuntu1804 run apt upgrade -y -<# -NOTE: Other distros can be scripted the same way for example: + <# + NOTE: Other distros can be scripted the same way for example: -#--- SLES --- -# Install SLES Store app -Invoke-WebRequest -Uri https://aka.ms/wsl-sles-12 -OutFile ~/SLES.appx -UseBasicParsing -Add-AppxPackage -Path ~/SLES.appx -# Launch SLES -sles-12.exe - -# --- openSUSE --- -Invoke-WebRequest -Uri https://aka.ms/wsl-opensuse-42 -OutFile ~/openSUSE.appx -UseBasicParsing -Add-AppxPackage -Path ~/openSUSE.appx -# Launch openSUSE -opensuse-42.exe -#> + #--- SLES --- + # Install SLES Store app + Invoke-WebRequest -Uri https://aka.ms/wsl-sles-12 -OutFile ~/SLES.appx -UseBasicParsing + Add-AppxPackage -Path ~/SLES.appx + # Launch SLES + sles-12.exe + # --- openSUSE --- + Invoke-WebRequest -Uri https://aka.ms/wsl-opensuse-42 -OutFile ~/openSUSE.appx -UseBasicParsing + Add-AppxPackage -Path ~/openSUSE.appx + # Launch openSUSE + opensuse-42.exe + #> +} \ No newline at end of file