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
@charris-msft
Copy link

crazy - first time I've seen this issue:
Running the script in PowerShell 7.3.2 failed, but running it in older PowerShell 5.1.20348.1366 succeeded. I'm sure there are more compatibility issues like this, but it's the first time I've hit one.

Here is the error I got under 7.3.2, and running Import-Module Appx fails on 7.3.2 as well.

Add-AppxPackage: C:\Users\arcdemo\Documents\Install-WindowsTerminal.ps1:16
Line |
  16 |  Add-AppxPackage -Path $framworkPkgPath
     |  ~~~~~~~~~~~~~~~
     | The 'Add-AppxPackage' command was found in the module 'Appx', but the module could not be loaded due to the
     | following error: [Operation is not supported on this platform. (0x80131539)] For more information, run
     | 'Import-Module Appx'.
Add-AppxPackage: C:\Users\arcdemo\Documents\Install-WindowsTerminal.ps1:17

Perhaps adding the following would help others in the future:
If ($PSVersionTable.PSVersion.Major -ge 7){ Write-Error "This script needs be run by version of PowerShell prior to 7.0" }

@likamrat
Copy link
Author

likamrat commented Feb 8, 2023

Thx @charris-msft. Updated

@SignFinder
Copy link

Needs to be clarified that it works only with Windows Server 2022, I think. WIndows Server 2019 does not fit.
"A Prerequisite for an install could not be satisfied.
Windows cannot install package Microsoft.WindowsTerminal_1.16.10261.0_x64__8wekyb3d8bbwe because this package is not co
mpatible with the device. The package requires OS version 10.0.19041.0 or higher on the Windows.Mobile device family. T
he device is currently running OS version 10.0.17763.2366."

@likamrat
Copy link
Author

Thx @SignFinder. Updated

@cheema-corellian
Copy link

I tried it and got the following error:

PS C:\Users\cheema> .\Terminal_WinSrv.ps1
Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At C:\Users\cheema\Terminal_WinSrv.ps1:16 char:24
+ Invoke-WebRequest -Uri $downloadUri -OutFile ( New-Item -Path $msiPat ...
+                        ~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Invoke-WebRequest], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF0, Package could not be opened.
error 0x8007000D: Opening the package from location Microsoft.WindowsTerminal.msixbundle failed.
NOTE: For additional information, look for [ActivityId] 9f8500d1-77a6-0002-1a58-39a0a677d901 in the Event Log or use the command line Get-AppPackageLog -ActivityID
9f8500d1-77a6-0002-1a58-39a0a677d901
At C:\Users\cheema\Terminal_WinSrv.ps1:20 char:1
+ Add-AppxPackage -Path $msiPath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (C:\WinTerminal\...inal.msixbundle:String) [Add-AppxPackage], FileNotFoundException
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

@dam012345DISW
Copy link

I tried it and got the following error:

PS C:\Users\cheema> .\Terminal_WinSrv.ps1
Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At C:\Users\cheema\Terminal_WinSrv.ps1:16 char:24
+ Invoke-WebRequest -Uri $downloadUri -OutFile ( New-Item -Path $msiPat ...
+                        ~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Invoke-WebRequest], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF0, Package could not be opened.
error 0x8007000D: Opening the package from location Microsoft.WindowsTerminal.msixbundle failed.
NOTE: For additional information, look for [ActivityId] 9f8500d1-77a6-0002-1a58-39a0a677d901 in the Event Log or use the command line Get-AppPackageLog -ActivityID
9f8500d1-77a6-0002-1a58-39a0a677d901
At C:\Users\cheema\Terminal_WinSrv.ps1:20 char:1
+ Add-AppxPackage -Path $msiPath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (C:\WinTerminal\...inal.msixbundle:String) [Add-AppxPackage], FileNotFoundException
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

same error today for me

@ysichrisdag
Copy link

I tried it and got the following error:

PS C:\Users\cheema> .\Terminal_WinSrv.ps1
Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At C:\Users\cheema\Terminal_WinSrv.ps1:16 char:24
+ Invoke-WebRequest -Uri $downloadUri -OutFile ( New-Item -Path $msiPat ...
+                        ~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Invoke-WebRequest], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF0, Package could not be opened.
error 0x8007000D: Opening the package from location Microsoft.WindowsTerminal.msixbundle failed.
NOTE: For additional information, look for [ActivityId] 9f8500d1-77a6-0002-1a58-39a0a677d901 in the Event Log or use the command line Get-AppPackageLog -ActivityID
9f8500d1-77a6-0002-1a58-39a0a677d901
At C:\Users\cheema\Terminal_WinSrv.ps1:20 char:1
+ Add-AppxPackage -Path $msiPath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (C:\WinTerminal\...inal.msixbundle:String) [Add-AppxPackage], FileNotFoundException
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

Not sure what used to be returned but this error is caused by the "-SkipLast 1" parameter on the select-object at the end of $downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url as this line currently only returns 1 item.

@ysichrisdag
Copy link

ysichrisdag commented Sep 28, 2023

The script also threw this error for me on server 2022 for a missing dependency "Microsoft.UI.Xaml.2.8" which can be resolved by pulling down and installing https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.5/Microsoft.UI.Xaml.2.8.x64.appx. I added this in my fork if you want to integrate it.

@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