Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active August 9, 2023 09:38
Show Gist options
  • Select an option

  • Save guitarrapc/9b7395e4bb63a74f068388a86365e255 to your computer and use it in GitHub Desktop.

Select an option

Save guitarrapc/9b7395e4bb63a74f068388a86365e255 to your computer and use it in GitHub Desktop.
Download and install winget v1.5.1881 to Windows Server 2022
# download
curl.exe -sSf -L -o "$env:UserProfile/Downloads/Microsoft.UI.Xaml.2.7.x64.appx" https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.7.3/Microsoft.UI.Xaml.2.7.x64.appx
curl.exe -sSf -L -o "$env:UserProfile/Downloads/Microsoft.VCLibs.x64.14.00.Desktop.appx" https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx
curl.exe -sSf -L -o "$env:UserProfile/Downloads/winget-cli.v1.5.1881.msixbundle" https://github.com/microsoft/winget-cli/releases/download/v1.5.1881/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
curl.exe -sSf -L -o "$env:UserProfile/Downloads/winget-cli-c6bee58ade21451eb54dc52e559a314c_License1.v1.5.1881.xml" https://github.com/microsoft/winget-cli/releases/download/v1.5.1881/c6bee58ade21451eb54dc52e559a314c_License1.xml
# install
Add-AppxPackage -Path "$env:UserProfile/Downloads/Microsoft.UI.Xaml.2.7.x64.appx"
Add-AppxPackage -Path "$env:UserProfile/Downloads/Microsoft.VCLibs.x64.14.00.Desktop.appx"
Add-AppxPackage -Path "$env:UserProfile/Downloads/winget-cli.v1.5.1881.msixbundle"
Add-AppxProvisionedPackage -Online -PackagePath "$env:UserProfile/Downloads/winget-cli.v1.5.1881.msixbundle" -LicensePath "$env:UserProfile/Downloads/winget-cli-c6bee58ade21451eb54dc52e559a314c_License1.v1.5.1881.xml"
# check installed
winget -v
# v1.5.1881
# accept source agreement and show packages
winget list --accept-source-agreements
winget install -e --silent --accept-source-agreements --id FooBar
function Get-ProcessVariable {
param([string]$Key)
[System.Environment]::GetEnvironmentVariable($Key, "Process")
}
function Set-ProcessVariable {
param([string]$Key, [string]$Value)
[System.Environment]::SetEnvironmentVariable($Key, $Value, "Process")
Get-SystemVariable -Key $SystemVariable
}
function Get-ProcessPath {
Get-ProcessVariable -Key PATH
}
function Set-ProcessPath {
param([string]$NewPath)
Set-ProcessVariable -Key PATH -Value $NewPath
}
function Get-UserVariable {
param([string]$Key)
[System.Environment]::GetEnvironmentVariable($Key, "User")
}
function Set-UserVariable {
param([string]$Key, [string]$Value)
[System.Environment]::SetEnvironmentVariable($Key, $Value, "User")
Get-SystemVariable -Key $SystemVariable
}
function Get-UserPath {
Get-UserVariable -Key PATH
}
function Set-UserPath {
param([string]$NewPath)
Set-UserVariable -Key PATH -Value $NewPath
}
function Get-SystemVariable {
param([string]$Key)
[System.Environment]::GetEnvironmentVariable($Key, "Machine")
}
function Set-SystemVariable {
param([string]$Key, [string]$Value)
[System.Environment]::SetEnvironmentVariable($Key, $Value, "Machine")
Get-SystemVariable -Key $SystemVariable
}
function Get-MachinePath {
Get-SystemVariable -Key PATH
}
function Set-MachinePath {
param([string]$NewPath)
Set-SystemVariable -Key PATH -Value $NewPath
}
function Test-MachinePath {
param([string]$PathItem)
$pathItems = (Get-MachinePath).Split(';')
$pathItems.Contains($PathItem)
}
function Add-MachinePathItem {
param([string]$PathItem)
$currentPath = Get-MachinePath
$newPath = $PathItem + ';' + $currentPath
Set-MachinePath -NewPath $newPath
}
# 現在のプロセスのPATHを更新する
# winget installed tool may add to Machine PATH or User PATH, but not to Process PATH. Propagate PATH to Process.
function Reload-ProcessPath {
$systemPath = Get-MachinePath
$userPath = Get-UserPath
Set-ProcessPath "${userPath};${systemPath}"
}
@guitarrapc
Copy link
Author

Base knowledge.

https://learn.microsoft.com/en-us/windows/package-manager/winget/

However you need foobar_License1.xml to activate winget. Refer to IoT installation guide.

https://learn.microsoft.com/en-us/windows/iot/iot-enterprise/deployment/install-winget-windows-iot

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