小ネタです。
先月リリースされたWindows Server 2022はOSのビルドバージョンとしては10.0.20348
でありWindows Terminalがインストール可能なビルドとなります。
というわけで誰もがWindows Server 2022にWindows Terminalをインストールしようと考えるに決まっており既に先駆者もいるわけです。
たとえば以下は元MVPで現Microsoft社員のThomas MaurerさんのブログでWindows Server 2022プレビュー時点から既に試されています。
まあ、OSのビルドバージョンさえクリアできていればインストール方法自体は非常にシンプルで、GitHubのリリースページからmsixbundleファイルをダウンロードしてやるだけです。
簡単なPowerShell関数を作りましたので以下のスクリプトを実行すれば最新のWindows Terminalをサクッとインストールできます。
現在最新のWindows Terminal 1.13以降ではインストーラーがWindows 10/Windows 11で分離したのに加え、Windows 10環境ではVC Runtimeの事前インストールが必要になっています。
Windows Server 2022ではWindows 10のインストール手順を行ってください。
#
# ※ブログ初回公開時と内容が異なります (2022年6月アップデート済み)
#
function Install-LatestWindowsTerminal ([switch]$SkipInstallVCLibs) {
# Check OS version
$buildVersion = [Version](Get-CimInstance -ClassName 'Win32_OperatingSystem' -Property Version | Select-Object -ExpandProperty Version)
$isWin11 = if ($buildVersion -ge ([Version]"10.0.22000.0") ) { $true } else { $false }
# Find the latest MSIX installer url
$latest = Invoke-RestMethod -Uri 'https://api.github.com/repos/microsoft/terminal/releases/latest'
$msixUrls = $latest.assets | Where-Object { $_.browser_download_url -like '*.msixbundle' } | Select-Object -ExpandProperty browser_download_url
$msixUrl = switch (@($msixUrls).Count) {
{ $_ -gt 1 } {
# Added for Windows 11
if ($isWin11) {
$msixUrls | Where-Object { $_ -like '*Win11*' }
break
}
$msixUrls | Where-Object { $_ -like '*Win10*' }
break
}
Default {
@($msixUrls)[0]
break
}
}
if ([string]::IsNullOrEmpty($msixUrl)) {
Write-Error 'Failed to get the installer url'
return
}
# For Windows 10, Need to install VCLibs
if ((-not $isWin11) -and (-not $SkipInstallVCLibs)) {
$vcLibsUrl = 'https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx'
$vcLibsPath = Join-Path -Path ([IO.Path]::GetTempPath()) ($vcLibsUrl -split '/')[-1]
Write-Host -ForegroundColor Green "Download $vcLibsUrl"
Invoke-WebRequest -Uri $vcLibsUrl -OutFile $vcLibsPath
Write-Host -ForegroundColor Green "Install $vcLibsPath"
Add-AppxPackage -Path $vcLibsPath
if (Test-Path -LiteralPath $vcLibsPath) {
Write-Host -ForegroundColor Green "Remove $vcLibsPath"
Remove-Item -LiteralPath $vcLibsPath
}
}
# Download MSIX
Write-Host -ForegroundColor Green "Download $msixUrl"
$msixPath = Join-Path -Path ([IO.Path]::GetTempPath()) ($msixUrl -split '/')[-1]
Invoke-WebRequest -Uri $msixUrl -OutFile $msixPath
# Install MSIX
Write-Host -ForegroundColor Green "Install $msixPath"
Add-AppxPackage -Path $msixPath
# Remove MSIX
if (Test-Path -LiteralPath $msixPath) {
Write-Host -ForegroundColor Green "Remove $msixPath"
Remove-Item -LiteralPath $msixPath
}
Write-Host -ForegroundColor Green "Installation complete!"
}
Install-LatestWindowsTerminal
これでよしなにWindows TerminalがインストールされWindows Server 2022で利用可能になります。
おまけ : Windows Package Manager Client (winget)をインストールする
現在Windows Server 2022上でのwingetの利用は試験的な機能扱いで非サポートなのでご注意ください。
Windows Terminalと同様の理屈でWindows Package Manager Client (winget)もインストール可能です。
wingetの場合はアプリケーションのmsixbunldeファイル以外にVCライブラリのインストールが必要となる点、ライセンスファイルも同時にインストールする必要があるためAdd-AppxProvisionedPackage
を使う必要がある点が異なります。
function Install-LatestWinGet ([bool]$installVCLibs = $true) {
# Install prerequisites
if ($installVCLibs) {
$vcLibsUrl = 'https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx'
$vcLibsPath = Join-Path -Path ([IO.Path]::GetTempPath()) ($vcLibsUrl -split '/')[-1]
Write-Host -ForegroundColor Green "Download $vcLibsUrl"
Invoke-WebRequest -Uri $vcLibsUrl -OutFile $vcLibsPath
Write-Host -ForegroundColor Green "Install $vcLibsPath"
Add-AppxPackage -Path $vcLibsPath
if (Test-Path -LiteralPath $vcLibsPath) {
Write-Host -ForegroundColor Green "Remove $vcLibsPath"
Remove-Item -LiteralPath $vcLibsPath
}
}
# Find the latest assets url
$latest = Invoke-RestMethod -Uri 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
$msixUrl = $latest.assets | Where-Object { $_.browser_download_url -like '*.msixbundle' } | Select-Object -ExpandProperty browser_download_url
$msixPath = Join-Path -Path ([IO.Path]::GetTempPath()) ($msixUrl -split '/')[-1]
$licenseUrl = $latest.assets | Where-Object { $_.browser_download_url -like '*License1.xml' } | Select-Object -ExpandProperty browser_download_url
$licensePath = Join-Path -Path ([IO.Path]::GetTempPath()) ($licenseUrl -split '/')[-1]
# Download assets
( @{Url = $msixUrl ; LocalPath = $msixPath}, @{Url = $licenseUrl ; LocalPath = $licensePath} ) | ForEach-Object {
Write-Host -ForegroundColor Green "Download $($_.Url)"
Invoke-WebRequest -Uri $_.Url -OutFile $_.LocalPath
}
# Install MSIX
Write-Host -ForegroundColor Green "Install $msixPath"
Write-Host -ForegroundColor Green " : License $licensePath"
Add-AppxProvisionedPackage -Online -PackagePath $msixPath -LicensePath $licensePath
# Remove assets
($msixPath, $licensePath) | ForEach-Object {
if (Test-Path -LiteralPath $_) {
Write-Host -ForegroundColor Green "Remove $_"
Remove-Item -LiteralPath $_
}
}
Write-Host -ForegroundColor Green "Installation complete!"
}
Install-LatestWinGet
これでwingetを使っていろいろなソフトウェアをインストールできます。
なお、wingetインストール後はログインし直してください。
(上図はVS Codeをインストールしてみた図)
Gist
一応私のGistにもコードを載せておきます。