Skip to content

Instantly share code, notes, and snippets.

@KZeronimo
Last active August 19, 2023 17:19
Show Gist options
  • Save KZeronimo/3dd360bece3341a322335469a0a813ea to your computer and use it in GitHub Desktop.
Save KZeronimo/3dd360bece3341a322335469a0a813ea to your computer and use it in GitHub Desktop.
Winget based Boxstarter Script - Full - Windows 10/11
# Set TLS 1.2
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
# Import Choco Install-*
Import-Module "$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1" -Force
# Set up choco cache location to work around Boxstarter Issue 241
$chocoCache = (Join-Path ([Environment]::GetEnvironmentVariable("LocalAppData")) "Temp\ChocoCache")
New-Item -Path $chocoCache -ItemType directory -Force
# Remove *.tmp from the choco cache directory so the ad-hoc package installs using Install-ChocolateyPackage behave idempotently - this is a hack
Remove-Item -Path (Join-Path $chocoCache '*.tmp') -Recurse -Force
# Get Post Build Content
Write-BoxstarterMessage "Getting post build content"
$path = "C:\_PostBuildContent"
$answersPath = "C:\Windows\Temp\User_Answers.json"
if (Test-Path -Path $path) {
Remove-Item -Path $path -Recurse
}
Invoke-WebRequest -UseBasicParsing https://github.com/KZeronimo/PostBuildContent/archive/refs/heads/master.zip -OutFile C:\PostBuildContent.zip
Expand-Archive -Path C:\PostBuildContent.zip -DestinationPath $path
Move-Item (Join-Path $path 'PostBuildContent-master\*') $path
if (Test-Path $answersPath) {
Copy-Item $answersPath -Destination (Join-Path $path 'User_Answers.json')
}
Remove-Item -Path (Join-Path $path 'PostBuildContent-master')
Remove-Item -Path C:\PostBuildContent.zip
# Configure Windows Explorer Options
Set-WindowsExplorerOptions -EnableShowFileExtensions -EnableShowHiddenFilesFoldersDrives -EnableShowFullPathInTitleBar
# Trust PSGallery
Get-PackageProvider -Name NuGet -ForceBootstrap
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
# Install Source Code Pro and Nerd Fonts
Write-BoxstarterMessage "Installing Source Code Pro and Source Code Pro Nerd Fonts"
cinst sourcecodepro --cacheLocation $chocoCache
cinst nerd-fonts-sourcecodepro --cacheLocation $chocoCache
# Install Cascadia Code Nerd Font
Write-BoxstarterMessage "Installing Cascadia Code Nerd & PL Font"
cinst nerd-fonts-cascadiacode --cacheLocation $chocoCache
$latestBrowserDownloadUrl = Invoke-WebRequest -UseBasicParsing -Uri "https://api.github.com/repos/microsoft/cascadia-code/releases/latest" | ConvertFrom-Json | Select-Object -ExpandProperty assets | Select-Object -ExpandProperty browser_download_url | Where-Object { $_ -match '.*\/[^\/]*OTF[^\/]*\.zip$|.*\/[^\/]*\.zip$' } | Select-Object -First 1
& C:\_PostBuildContent\helpers\install-font.ps1 -Url $latestBrowserDownloadUrl -FontFilesFilter '*.otf'
# Install oh-my-posh
Write-BoxstarterMessage "Installing posh-git and oh-my-posh"
Install-Module -Name posh-git -Scope CurrentUser
winget install JanDeDobbeleer.OhMyPosh --source winget --silent --accept-source-agreements --accept-package-agreements
# Install PowerShell Core
Write-BoxstarterMessage "Installing PowerShell Core"
winget install Microsoft.PowerShell --source winget --silent --accept-source-agreements --accept-package-agreements
# Install Git (core credential mgr intalled with git for windows)
Write-BoxstarterMessage "Installing Git"
winget install Git.Git --source winget --silent --accept-source-agreements --accept-package-agreements
# Install Window Terminal
Write-BoxstarterMessage "Installing Windows Terminal"
winget install 9N0DX20HK701 --source msstore --silent --accept-source-agreements --accept-package-agreements
# Install Visual Studio Code
Write-BoxstarterMessage "Installing VS Code"
winget install Microsoft.VisualStudioCode --source winget --silent --accept-source-agreements --accept-package-agreements
# Install Notepad++
Write-BoxstarterMessage "Installing Notepad++"
winget install Notepad++.Notepad++ --source winget --silent --accept-source-agreements --accept-package-agreements
# Install Google Chrome
Write-BoxstarterMessage "Installing Chrome"
winget install Google.Chrome --source winget --silent --accept-source-agreements --accept-package-agreements
# Cloud Full Begin
# Install PowerShell Azure Modules
Write-BoxstarterMessage "Installing Azure PowerShell modules"
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery
# Install posh-docker docker
Write-BoxstarterMessage "Installing Docker Completion"
Install-Module -Name DockerCompletion -Scope CurrentUser
# Install Azure CLI
Write-BoxstarterMessage "Installing Azure CLI"
winget install Microsoft.AzureCLI --source winget --silent --accept-source-agreements --accept-package-agreements
# Install NuGet Command Line
Write-BoxstarterMessage "Installing NuGet CLI"
winget install Microsoft.NuGet --source winget --silent --accept-source-agreements --accept-package-agreements
# Install Azure Data Studio
Write-BoxstarterMessage "Installing Azure Data Studio"
winget install Microsoft.AzureDataStudio --source winget --silent --accept-source-agreements --accept-package-agreements
# Install Sql Server Mgmt Studio?
# Install Azure IoT Hub Device Explorer Xplat
Write-BoxstarterMessage "Installing Azure IoT Hub Device Explorer Xplat"
winget install Microsoft.Azure.IoTExplorer --source winget --silent --accept-source-agreements --accept-package-agreements
# Install Microsoft Azure Storage Explorer
Write-BoxstarterMessage "Installing Azure Storage Explorer"
winget install Microsoft.Azure.StorageExplorer --source winget --silent --accept-source-agreements --accept-package-agreements
# Install NuGet Package Explorer
Write-BoxstarterMessage "Installing NuGet Package Explorer"
winget install 9WZDNCRDMDM3 --source msstore --silent --accept-source-agreements --accept-package-agreements
# Install Service Bus Explorer
Write-BoxstarterMessage "Installing Service Bus Explorer"
winget install paolosalvatori.ServiceBusExplorer --source winget --silent --accept-source-agreements --accept-package-agreements
Install-ChocolateyShortcut -ShortcutFilePath (Join-Path $env:AppData "Microsoft\Windows\Start Menu\Programs\Service Bus Explorer.lnk") -TargetPath (Join-Path $env:LocalAppData "Microsoft\WinGet\Packages\paolosalvatori.ServiceBusExplorer_Microsoft.Winget.Source_8wekyb3d8bbwe\ServiceBusExplorer.exe")
# Install LINQPad
Write-BoxstarterMessage "Installing LINQPad"
winget install LINQPad.LINQPad.7 --source winget --silent --accept-source-agreements --accept-package-agreements
# Install Node.js
Write-BoxstarterMessage "Installing NodeJS"
winget install OpenJS.NodeJS.LTS --source winget --silent --accept-source-agreements --accept-package-agreements
# Install Postman
Write-BoxstarterMessage "Installing Postman"
winget install Postman.Postman --source winget --silent --accept-source-agreements --accept-package-agreements
# Install Python
# Write-BoxstarterMessage "Installing Python"
# winget install Python.Python.3.12 --source winget --silent --accept-source-agreements --accept-package-agreements
# Refresh Environment
Write-BoxstarterMessage "Refresh Environment"
refreshenv
# Azure Cli Extenstion
Write-BoxstarterMessage "Installing Az Cli Extenstions "
az extension add --name azure-iot
az extension add --name containerapp
# Install Visual Studio
Write-BoxstarterMessage "Installing Visual Studio"
& C:\_PostBuildContent\helpers\install-vs2022.ps1
# Install Visual Studio Extensions
Write-BoxstarterMessage "Installing Visual Studio Extensions"
& C:\_PostBuildContent\helpers\install-vs2022-vsix.ps1
$virtualizationSlatSupport = (Get-WmiObject -Class 'Win32_Processor' | Select-Object -Property 'SecondLEvelAddressTranslationExtensions' -First 1)
if ([bool]($virtualizationSlatSupport.PSobject.Properties.name -match 'SecondLEvelAddressTranslationExtensions') -and $virtualizationSlatSupport.SecondLEvelAddressTranslationExtensions) {
Write-BoxstarterMessage "Virtualization supported";
# Install additional components needed for Azure IoT Edge in VS
# Prefer https://github.com/Azure/iotedgedev/blob/main/docs/environment-setup/run-devcontainer-docker.md over local install of tools
# https://learn.microsoft.com/en-us/azure/iot-edge/how-to-visual-studio-develop-module?view=iotedge-1.4&pivots=iotedge-dev-ext
# Write-BoxstarterMessage "Installing additional components needed for Azure IoT Edge in VS
# pip install --upgrade iotedgehubdev
# Set-Location -Path C:\_PostBuildContent
# $path = "https://github.com/Microsoft/vcpkg"
# if (! (Test-Path -Path ($path -split '/')[-1])) {
# git clone $path
# Set-Location -Path C:\_PostBuildContent\vcpkg
# .\bootstrap-vcpkg.bat
# .\vcpkg.exe install azure-iot-sdk-c:x64-windows
# .\vcpkg.exe --triplet x64-windows integrate install
# }
# Set-Location -Path C:\Windows\system32
# Install and configur WSL
Write-BoxstarterMessage "Installing and configuring WSL"
wsl --install
# Install Docker Desktop
Write-BoxstarterMessage "Installing Docker Desktop"
winget install Docker.DockerDesktop --source winget --silent --accept-source-agreements --accept-package-agreements
# Enable Windows Sandbox
cinst Containers-DisposableClientVM -source windowsFeatures --cacheLocation $chocoCache
# Enable Hyper-V - Docker Windows Containers
# cinst Microsoft-Hyper-V-All -source windowsFeatures --cacheLocation $chocoCache
# Note Windows Hypervisor Platform is not installed because its not compatible with Packer
# Enable Containers - Docker Windows Containers
# cinst Containers -source windowsFeatures --cacheLocation $chocoCache
# Create Hyper-V Off boot option
# Write-BoxstarterMessage "Creating Hyper-V Off boot option"
# bcdedit /copy '{current}' /d "Windows 10 - No Hyper-V" | ForEach-Object { $id = $_.Substring(($_.IndexOf('{')), (($_.IndexOf('}')) - ($_.IndexOf('{'))) + 1); bcdedit /set $id hypervisorlaunchtype Off }
}
else {
Write-Host "Virtualization NOT supported";
}
# Cloud Full End
# Create root folder structure
Write-BoxstarterMessage "Creating root folder structure"
New-Item -Path "C:\_Src" -Type Directory -Force
New-Item -Path "C:\_Src\Prod" -Type Directory -Force
New-Item -Path "C:\_Src\Prod\Mesh" -Type Directory -Force
New-Item -Path "C:\_Src\Sdbx" -Type Directory -Force
# Remove Desktop Shortcuts
Write-BoxstarterMessage "Removing desktop shortcuts"
Get-ChildItem -Path "C:\Users\*\Desktop\*" -Recurse -Include *.lnk | Remove-Item -Force
# Deploy post build content
Write-BoxstarterMessage "Deploying post build content"
if (! (Test-Path -Path (Join-Path $env:UserProfile ".gitconfig"))) {
Copy-Item "C:\_PostBuildContent\git\.gitconfig" -Destination $env:UserProfile -Force
}
Copy-Item "C:\_PostBuildContent\terminal\Microsoft.PowerShell_profile.ps1" -Destination (New-Item (Join-Path $env:UserProfile "Documents\WindowsPowerShell") -Type container -Force) -Force
Copy-Item "C:\_PostBuildContent\terminal\Microsoft.PowerShell_profile.ps1" -Destination (New-Item (Join-Path $env:UserProfile "Documents\PowerShell") -Type container -Force) -Force
Copy-Item "C:\_PostBuildContent\terminal\wt_profiles_settings.json" -Destination (Join-Path $env:LocalAppData "Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json") -Force
Copy-Item "C:\_PostBuildContent\terminal\agnoster-mesh.omp.json" -Destination (Join-Path $env:LocalAppData "Programs\oh-my-posh\themes\agnoster-mesh.omp.json") -Force
Copy-Item -Path "C:\_PostBuildContent\themes\*" -Destination (New-Item (Join-Path $env:UserProfile "Pictures\Themes") -Type container -Force) -Recurse -Force
Copy-Item -Path "C:\_PostBuildContent\layouts\*" -Destination $env:LocalAppData -Recurse -Force
# Configure my .gitconfig
Write-BoxstarterMessage "Customizing gitconfig"
& C:\_PostBuildContent\git\configure-my-gitconfig.ps1
# Setup configuration and dotfile tracking
$path = Join-Path $env:UserProfile ".myconf"
New-Item -Path ($path) -Type Directory -Force
Set-Location -Path $path
if (! (Test-Path -Path "HEAD")) {
Write-BoxstarterMessage "Setting up configuration and dotfile tracking"
git init --bare $path
Write-Output '*' >> $env:UserProfile/.myconf/info/exclude
}
# Clone OneFlow Repo
Set-Location -Path C:\_Src\Prod\Mesh
$path = "https://meshsystems@dev.azure.com/meshsystems/Mesh%20Systems/_git/Mesh.DevAutomation.OneFlow"
if (! (Test-Path -Path ($path -split '/')[-1])) {
Write-BoxstarterMessage "Cloning OneFlow repo"
git clone $path
}
# Clone DotNet Templates Repo
Set-Location -Path C:\_Src\Prod\Mesh
$path = "https://meshsystems@dev.azure.com/meshsystems/Mesh%20Systems/_git/Mesh.DotNet.Templates"
if (! (Test-Path -Path ($path -split '/')[-1])) {
Write-BoxstarterMessage "Cloning DotNet Templates repo"
git clone $path
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment