Bootstrapping a New Windows Installation with Winget
Setting up a new Windows installation can be a daunting task, but with the help of the Windows Package Manager (winget), it can be made easier. Winget is a command-line tool that allows you to install packages and applications on your Windows machine with ease. In this article, we will focus on how to use winget to install packages during a new Windows installation, and how to bootstrap the process using scripts.
What is Winget?
Winget is a free, open-source package manager for Windows 10 and higher. It allows you to install, update, and manage packages and applications on your Windows machine using a command-line interface. Winget uses a manifest-based system, where each package has a manifest file that contains information about the package, such as its name, version, and dependencies. This makes it easy to discover and install packages, as well as to ensure that dependencies are installed correctly.
Bootstrapping a New Windows Installation
Bootstrapping a new Windows installation involves setting up the system with all the necessary packages and applications. This can be a time-consuming process, but with the help of winget and some scripting, it can be automated. Here's how:
Step 1: Install Winget
The first step is to install winget on your new Windows installation. This can be done by running the following command in an elevated PowerShell prompt:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
This command will install the Chocolatey package manager, which includes winget. Once Chocolatey is installed, you can verify that winget is installed by running the following command:
winget --version
Step 2: Create a Script
Next, create a script that will install the necessary packages using winget. Here's an example script:
@echo off
setlocal
REM Install packages using winget
winget install --id=Microsoft.PowerToys
winget install --id=Microsoft.VisualStudioCode
winget install --id=Microsoft.WindowsTerminal
endlocal
This script installs three packages: PowerToys, Visual Studio Code, and Windows Terminal. You can customize this script to install the packages that you need.
Step 3: Call the Script from Another Script
Finally, you can call the script from another script to automate the entire process. Here's an example:
@echo off
setlocal
REM Install packages using winget
call "%~dp0install-packages.bat"
REM Configure settings
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v StartupPage /t REG_SZ /d "" /f
REM Restart Explorer
taskkill /im explorer.exe /f
start explorer.exe
endlocal
This script installs the packages using the previous script, configures some settings, and restarts Explorer to apply the changes. You can customize this script to perform any additional setup tasks that you need.
Bootstrapping a new Windows installation can be a time-consuming process, but with the help of winget and some scripting, it can be automated. By creating a script that installs the necessary packages using winget, you can save time and ensure that your new Windows installation is set up correctly. In this article, we have covered the basics of using winget to install packages, and how to use it to bootstrap a new Windows installation. Happy scripting!