👌

Wingetでインストールを行う (PowerShellスクリプト)

2021/10/16に公開

Wingetでインストールを行うPowerShellスクリプトです。

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

	if (-Not (Get-Command("winget.exe"))) {
		Write-Error -Message "winget.exe is not installed." -ErrorAction Stop
		return 1603
	}

	# Require "-PassThru" option to get ExitCode
	[System.Diagnostics.Process] $process = Start-Process `
		-FilePath "winget.exe" `
		-ArgumentList "install -e --id $id" `
		-NoNewWindow `
		-PassThru `
		-Wait

	return $process.ExitCode
}

Discussion