# 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 the specified 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 }