Skip to content

Instantly share code, notes, and snippets.

@likamrat
Last active June 3, 2024 17:32
Show Gist options
  • Save likamrat/726974f4715d164a4013f7cab2183e3c to your computer and use it in GitHub Desktop.
Save likamrat/726974f4715d164a4013f7cab2183e3c to your computer and use it in GitHub Desktop.
Install Windows Terminal on Windows Server
Write-Information "This script needs be run on Windows Server 2019 or 2022"
If ($PSVersionTable.PSVersion.Major -ge 7){ Write-Error "This script needs be run by version of PowerShell prior to 7.0" }
# Define environment variables
$downloadDir = "C:\WinTerminal"
$gitRepo = "microsoft/terminal"
$filenamePattern = "*.msixbundle"
$framworkPkgUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx"
$framworkPkgPath = "$downloadDir\Microsoft.VCLibs.x64.14.00.Desktop.appx"
$msiPath = "$downloadDir\Microsoft.WindowsTerminal.msixbundle"
$releasesUri = "https://api.github.com/repos/$gitRepo/releases/latest"
$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url | Select-Object -SkipLast 1
# Download C++ Runtime framework packages for Desktop Bridge and Windows Terminal latest release msixbundle
Invoke-WebRequest -Uri $framworkPkgUrl -OutFile ( New-Item -Path $framworkPkgPath -Force )
Invoke-WebRequest -Uri $downloadUri -OutFile ( New-Item -Path $msiPath -Force )
# Install C++ Runtime framework packages for Desktop Bridge and Windows Terminal latest release
Add-AppxPackage -Path $framworkPkgPath
Add-AppxPackage -Path $msiPath
# Cleanup
Remove-Item $downloadDir -Recurse -Force
@sql-sith
Copy link

sql-sith commented Jun 3, 2024

I think that the | Select-Object -SkipLast 1 bit needs to be removed now. Perhaps something has changed recently in the output of that command.

@sql-sith
Copy link

sql-sith commented Jun 3, 2024

I tried to run this on Windows Server 2019, but the build number was too small. So I ran it on Windows Server 2022, and now it just won't launch. I am weeping, bitterly, without even slicing any onions. Any ideas as to why this might happen?

@sql-sith
Copy link

sql-sith commented Jun 3, 2024

Sorry, I should have given the error message:

PS C:\Windows\system32> wt.exe; $error[0]
Program 'wt.exe' failed to run: The file cannot be accessed by the systemAt line:1 char:1
+ wt.exe; $error[0]
+ ~~~~~~.
At line:1 char:1
+ wt.exe; $error[0]
+ ~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

Program 'wt.exe' failed to run: The file cannot be accessed by the systemAt line:1 char:1
+ wt.exe; $error[0]
+ ~~~~~~.
At line:1 char:1
+ wt.exe; $error[0]
+ ~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed                             

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment