| 1 | <# |
| 2 | .SYNOPSIS |
| 3 | Downloads and provisions Windows Terminal system-wide for all users. |
| 4 | |
| 5 | .DESCRIPTION |
| 6 | Automates the download, extraction, and system-wide provisioning of Microsoft Windows Terminal |
| 7 | using the official GitHub PreinstallKit release bundle. |
| 8 | |
| 9 | The script dynamically queries the GitHub API for the latest non-prerelease build, downloads |
| 10 | the zip payload, and provisions the MSIX bundle alongside its dependencies and XML license |
| 11 | for all current and future user accounts on the local machine. |
| 12 | |
| 13 | .EXAMPLE |
| 14 | irm https://gist.ergosteur.com/ergosteur/install-windowsterminal/raw/HEAD/install-windowsterminal.ps1 | iex |
| 15 | Downloads and executes the script remotely via an elevated PowerShell session. |
| 16 | |
| 17 | .EXAMPLE |
| 18 | .\install-terminal.ps1 |
| 19 | Executes the script locally from an elevated PowerShell session. |
| 20 | |
| 21 | .NOTES |
| 22 | Prerequisites: |
| 23 | - Must run in an Elevated PowerShell Session (Run as Administrator). |
| 24 | - Requires Windows 10 or Windows 11 with DISM support (`Add-AppxProvisionedPackage`). |
| 25 | - Internet connectivity to access GitHub APIs and download asset binaries. |
| 26 | |
| 27 | Key Features: |
| 28 | - Auto-Discovery: Dynamically fetches the latest stable non-prerelease PreinstallKit release asset. |
| 29 | - Resilient Fallback: Defaults to a target fallback release URL if GitHub API calls fail or hit rate limits. |
| 30 | - Multi-User Provisioning: Binds license and dependencies (`Microsoft.UI.Xaml`) across all system user profiles. |
| 31 | - Automated Cleanup: Utilizes try/finally blocks to guarantee removal of temp files from `$env:TEMP`. |
| 32 | |
| 33 | .LINK |
| 34 | https://github.com/microsoft/terminal |
| 35 | #> |
| 36 | |
| 37 | # Requires Elevated PowerShell Session |
| 38 | if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { |
| 39 | throw "This script must be executed in a PowerShell session running as Administrator." |
| 40 | } |
| 41 | |
| 42 | $ErrorActionPreference = 'Stop' |
| 43 | $tempDir = Join-Path $env:TEMP "WT_Install_$([Guid]::NewGuid().Guid)" |
| 44 | New-Item -ItemType Directory -Path $tempDir -Force | Out-Null |
| 45 | |
| 46 | try { |
| 47 | # Fetch latest stable non-prerelease release from GitHub API |
| 48 | Write-Host "Querying GitHub API for the latest non-prerelease Terminal release..." -ForegroundColor Cyan |
| 49 | $releaseUrl = "https://api.github.com/repos/microsoft/terminal/releases/latest" |
| 50 | $release = Invoke-RestMethod -Uri $releaseUrl -Headers @{ "User-Agent" = "PowerShell" } |
| 51 | $asset = $release.assets | Where-Object { $_.name -like "*PreinstallKit.zip" } | Select-Object -First 1 |
| 52 | |
| 53 | # Use dynamically fetched URL or fallback to explicit release URL |
| 54 | $downloadUrl = if ($asset) { |
| 55 | $asset.browser_download_url |
| 56 | } else { |
| 57 | "https://github.com/microsoft/terminal/releases/download/v1.24.11911.0/Microsoft.WindowsTerminal_1.24.11911.0_8wekyb3d8bbwe.msixbundle_Windows10_PreinstallKit.zip" |
| 58 | } |
| 59 | |
| 60 | # Download and extract the PreinstallKit archive |
| 61 | $zipPath = Join-Path $tempDir "PreinstallKit.zip" |
| 62 | $extractPath = Join-Path $tempDir "Extracted" |
| 63 | |
| 64 | Write-Host "Downloading preinstallation kit..." -ForegroundColor Cyan |
| 65 | Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing |
| 66 | Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force |
| 67 | |
| 68 | # Locate package files from extracted archive |
| 69 | $bundle = (Get-ChildItem -Path $extractPath -Filter "*.msixbundle" -Recurse).FullName |
| 70 | $license = (Get-ChildItem -Path $extractPath -Filter "*License*.xml" -Recurse).FullName |
| 71 | $deps = (Get-ChildItem -Path $extractPath -Filter "Microsoft.UI.Xaml*.appx" -Recurse).FullName |
| 72 | |
| 73 | # Provision package system-wide for all users |
| 74 | Write-Host "Provisioning Windows Terminal across all user profiles..." -ForegroundColor Cyan |
| 75 | $params = @{ |
| 76 | Online = $true |
| 77 | PackagePath = $bundle |
| 78 | LicensePath = $license |
| 79 | DependencyPackagePath = $deps |
| 80 | } |
| 81 | Add-AppxProvisionedPackage @params | Out-Null |
| 82 | Write-Host "Successfully installed Windows Terminal system-wide!" -ForegroundColor Green |
| 83 | |
| 84 | } finally { |
| 85 | # Clean up temporary downloaded files |
| 86 | Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue |
| 87 | } |
ergosteur / Install Windows Terminal PowerShell Script
Last active 1 month ago
Script to install Windows Terminal directly from Github Releases.
Revision 1db15ab1b8595863bf29e3e09901a2b24b3ac5f0