🌊

Appxファイルをインストールする (PowerShellスクリプト)

2021/10/16に公開

AppxファイルをインストールするPowerShellスクリプトです。

function global:Install-App-Appx([string] $uri) {
	if ([string]::IsNullOrEmpty($uri)) {
		Write-Error -Message "Invalid Uri" -ErrorAction Stop
		return 1603
	}

	[string] $filePath = Join-Path $Env:Temp ([Guid]::NewGuid().ToString() + ".appx")
	Invoke-WebRequest -Uri $uri -OutFile $filePath -UseBasicParsing
	if ((-not (Test-Path $filePath)) -or ((Get-Item $filePath).Length -eq 0)) {
		return 1603
	}
	Add-AppxPackage -Path $filePath
	Remove-Item $filePath

	return 0
}

Discussion