Like 0

Script to install Windows Terminal directly from Github Releases.

Revision 1638369afab48e4445575d8eb54cfb065c3a5db7

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