<# .SYNOPSIS Downloads and provisions Windows Terminal system-wide for all users. .DESCRIPTION Automates the download, extraction, and system-wide provisioning of Microsoft Windows Terminal using the official GitHub PreinstallKit release bundle. The script dynamically queries the GitHub API for the latest non-prerelease build, downloads the zip payload, and provisions the MSIX bundle alongside its dependencies and XML license for all current and future user accounts on the local machine. .EXAMPLE irm https://gist.ergosteur.com/ergosteur/install-windowsterminal/raw/HEAD/install-windowsterminal.ps1 | iex Downloads and executes the script remotely via an elevated PowerShell session. .EXAMPLE .\install-terminal.ps1 Executes the script locally from an elevated PowerShell session. .NOTES Prerequisites: - Must run in an Elevated PowerShell Session (Run as Administrator). - Requires Windows 10 or Windows 11 with DISM support (`Add-AppxProvisionedPackage`). - Internet connectivity to access GitHub APIs and download asset binaries. Key Features: - Auto-Discovery: Dynamically fetches the latest stable non-prerelease PreinstallKit release asset. - Resilient Fallback: Defaults to a target fallback release URL if GitHub API calls fail or hit rate limits. - Multi-User Provisioning: Binds license and dependencies (`Microsoft.UI.Xaml`) across all system user profiles. - Automated Cleanup: Utilizes try/finally blocks to guarantee removal of temp files from `$env:TEMP`. .LINK https://github.com/microsoft/terminal #> # Requires Elevated PowerShell Session if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw "This script must be executed in a PowerShell session running as Administrator." } $ErrorActionPreference = 'Stop' $tempDir = Join-Path $env:TEMP "WT_Install_$([Guid]::NewGuid().Guid)" New-Item -ItemType Directory -Path $tempDir -Force | Out-Null try { # Fetch latest stable non-prerelease release from GitHub API Write-Host "Querying GitHub API for the latest non-prerelease Terminal release..." -ForegroundColor Cyan $releaseUrl = "https://api.github.com/repos/microsoft/terminal/releases/latest" $release = Invoke-RestMethod -Uri $releaseUrl -Headers @{ "User-Agent" = "PowerShell" } $asset = $release.assets | Where-Object { $_.name -like "*PreinstallKit.zip" } | Select-Object -First 1 # Use dynamically fetched URL or fallback to explicit release URL $downloadUrl = if ($asset) { $asset.browser_download_url } else { "https://github.com/microsoft/terminal/releases/download/v1.24.11911.0/Microsoft.WindowsTerminal_1.24.11911.0_8wekyb3d8bbwe.msixbundle_Windows10_PreinstallKit.zip" } # Download and extract the PreinstallKit archive $zipPath = Join-Path $tempDir "PreinstallKit.zip" $extractPath = Join-Path $tempDir "Extracted" Write-Host "Downloading preinstallation kit..." -ForegroundColor Cyan Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force # Locate package files from extracted archive $bundle = (Get-ChildItem -Path $extractPath -Filter "*.msixbundle" -Recurse).FullName $license = (Get-ChildItem -Path $extractPath -Filter "*License*.xml" -Recurse).FullName $deps = (Get-ChildItem -Path $extractPath -Filter "Microsoft.UI.Xaml*.appx" -Recurse).FullName # Provision package system-wide for all users Write-Host "Provisioning Windows Terminal across all user profiles..." -ForegroundColor Cyan $params = @{ Online = $true PackagePath = $bundle LicensePath = $license DependencyPackagePath = $deps } Add-AppxProvisionedPackage @params | Out-Null Write-Host "Successfully installed Windows Terminal system-wide!" -ForegroundColor Green } finally { # Clean up temporary downloaded files Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue }