Like 0

Script to install Windows Terminal directly from Github Releases.

Revision 75caa68f9a82105833db18ca7ea206dadb4e464a

Install-WindowsTerminal.ps1 Raw
1# Requires Elevated PowerShell Session
2if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
3 throw "This script must be executed in a PowerShell session running as Administrator."
4}
5
6$ErrorActionPreference = 'Stop'
7$tempDir = Join-Path $env:TEMP "WT_Install_$([Guid]::NewGuid().Guid)"
8New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
9
10try {
11 # Fetch latest stable non-prerelease release from GitHub API
12 Write-Host "Querying GitHub API for the latest non-prerelease Terminal release..." -ForegroundColor Cyan
13 $releaseUrl = "https://api.github.com/repos/microsoft/terminal/releases/latest"
14 $release = Invoke-RestMethod -Uri $releaseUrl -Headers @{ "User-Agent" = "PowerShell" }
15 $asset = $release.assets | Where-Object { $_.name -like "*PreinstallKit.zip" } | Select-Object -First 1
16
17 # Use dynamically fetched URL or fallback to the specified release URL
18 $downloadUrl = if ($asset) {
19 $asset.browser_download_url
20 } else {
21 "https://github.com/microsoft/terminal/releases/download/v1.24.11911.0/Microsoft.WindowsTerminal_1.24.11911.0_8wekyb3d8bbwe.msixbundle_Windows10_PreinstallKit.zip"
22 }
23
24 # Download and extract the PreinstallKit archive
25 $zipPath = Join-Path $tempDir "PreinstallKit.zip"
26 $extractPath = Join-Path $tempDir "Extracted"
27
28 Write-Host "Downloading preinstallation kit..." -ForegroundColor Cyan
29 Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing
30 Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force
31
32 # Locate package files from extracted archive
33 $bundle = (Get-ChildItem -Path $extractPath -Filter "*.msixbundle" -Recurse).FullName
34 $license = (Get-ChildItem -Path $extractPath -Filter "*License*.xml" -Recurse).FullName
35 $deps = (Get-ChildItem -Path $extractPath -Filter "Microsoft.UI.Xaml*.appx" -Recurse).FullName
36
37 # Provision package system-wide for all users
38 Write-Host "Provisioning Windows Terminal across all user profiles..." -ForegroundColor Cyan
39 $params = @{
40 Online = $true
41 PackagePath = $bundle
42 LicensePath = $license
43 DependencyPackagePath = $deps
44 }
45 Add-AppxProvisionedPackage @params | Out-Null
46 Write-Host "Successfully installed Windows Terminal system-wide!" -ForegroundColor Green
47
48} finally {
49 # Clean up temporary downloaded files
50 Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
51}