Last active
March 14, 2022 14:13
-
-
Save andrefcdias/12557354cfa562e195176bbd4c584f02 to your computer and use it in GitHub Desktop.
Making Windows great for Development (deprecated)
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 | |
<# Coolest development environment setup script in the block (Part 1) | |
⚠️ WARNING: This script was created to setup WSL before the new easy installation and was not tested under more recent versions of Windows 11. | |
Please follow my other guide that uses the new modern installations https://gist.github.com/andrefcdias/e1435ae4458024ece36a3b93e3cdd24f | |
--------------------------------------------------------- | |
Before running the script: | |
Make sure to run `Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process` | |
before running the script in an admin Powershell session. | |
See more at https:/go.microsoft.com/fwlink/?LinkID=135170. | |
This script will also set the Execution Policy to Unrestricted | |
so it can run part 2 of the script after the reboot. | |
What can I expect from this script? | |
This will install basic dev stuff like: | |
- WinGet v1.0.11451 | |
- PowerToys | |
- Windows Terminal | |
- Visual Studio Code | |
- Activate WSL feature | |
#> | |
# Set script to stop on errors | |
Set-StrictMode -Version Latest | |
$ErrorActionPreference = "Stop" | |
$PSDefaultParameterValues['*:ErrorAction']='Stop' | |
$client = new-object System.Net.WebClient | |
# File download URIs | |
$wingetDownloadUri = "https://github.com/microsoft/winget-cli/releases/download/v1.0.11451/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.appxbundle" | |
$part2Uri = "https://gist.githubusercontent.com/raw/0340e2609798ac6ef45198fa3a936ebb" | |
function hello() { | |
echo "" | |
Write-Host -ForegroundColor White "Welcome to the coolest development environment setup script!" | |
echo "" | |
echo "Please make sure you don't have any work pending saving." | |
echo "This script will need to restart your computer due to WSL/Hyper-V feature activations." | |
echo "" | |
pause | |
echo "" | |
} | |
function setup() { | |
echo "" | |
echo "> WinGet installation to facillitate the installation process" | |
echo "" | |
echo "Activating Developer Mode to manually install WinGet..." | |
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1" | Out-Null | |
echo "Developer Mode activated!" | |
echo "" | |
echo "Downloading Winget..." | |
$client.DownloadFile($wingetDownloadUri, "$env:TEMP/winget.appxbundle") | |
echo "WinGet downloaded!" | |
echo "" | |
echo "Installing WinGet..." | |
Add-AppxPackage -Path $env:TEMP/winget.appxbundle | |
echo "WinGet installed!" | |
# Configure WinGet to fetch from MS Store | |
# echo '{"$schema":"https://aka.ms/winget-settings.schema.json","experimentalFeatures":{"experimentalMSStore":true}}' > $Env:LOCALAPPDATA\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json | |
echo "" | |
} | |
function installApps { | |
echo "" | |
echo "> Installing helpful development apps" | |
echo "" | |
echo "Installing Powershell Core..." | |
winget install "Powershell" | Out-Null | |
echo "Powershell Core installed!" | |
echo "" | |
echo "Installing PowerToys..." | |
winget install "PowerToys" | Out-Null | |
echo "PowerToys installed!" | |
echo "" | |
echo "Installing Windows Terminal..." | |
winget install "Windows Terminal" | Out-Null | |
echo "Windows Terminal installed!" | |
echo "" | |
echo "Installing Visual Studio Code..." | |
winget install "Visual Studio Code (System Installer - x64)" --silent | Out-Null | |
echo "Visual Studio Code installed!" | |
echo "Closing that pesky VSCode window that opens after installation" | |
Get-Process | Where-Object {$_.ProcessName -eq "Code"} | Stop-Process | |
echo "" | |
} | |
function preparePartTwo { | |
echo "" | |
echo "> Setting up part 2 of script to run after restart" | |
echo "" | |
echo "Downloading the script from $part2Uri into $env:USERPROFILE..." | |
$client.DownloadFile($part2Uri, "$env:USERPROFILE/dev-env-setup-part-2.ps1") | Out-Null | |
echo "Script downloaded!" | |
echo "" | |
echo "Creating Scheduled Task to run on login..." | |
$setupAction = New-ScheduledTaskAction -Execute "powershell" -Argument "%USERPROFILE%/dev-env-setup-part-2.ps1" | |
$startupTrigger = New-ScheduledTaskTrigger -AtLogon -User "$env:USERDOMAIN\$env:USERNAME" | |
Register-ScheduledTask -Action $setupAction -Trigger $startupTrigger -RunLevel Highest -TaskName "Setup Development Environment" -Description "Task to autorun part 2 of the development environment setup script" | Out-Null | |
echo "Scheduled Task created!" | |
echo "" | |
echo "Your computer will be restarted now." | |
echo "If you have pending work, please cancel the script/close the console and restart ASAP." | |
echo "To continue with the restart, press ENTER." | |
pause | |
Restart-Computer | |
} | |
function installWSL { | |
echo "" | |
echo "> Setting up WSL" | |
echo "" | |
echo "Activating the WSL feature..." | |
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart | Out-Null | |
echo "WSL activated!" | |
echo "" | |
echo "Activating the Hyper-V feature..." | |
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart | Out-Null | |
echo "Hyper-V activated!" | |
echo "" | |
echo "Setting the Execution Policy to Unrestricted for the CurrentUser scope, so the script can continue after reboot..." | |
Set-ExecutionPolicy -Scope CurrentUser Unrestricted -Force | |
echo "Policy set!" | |
preparePartTwo | |
echo "" | |
} | |
hello | |
setup | |
installApps | |
installWSL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment