09-07-2022 02:37 AM
Hey
Recently I came across this great post by Rudy (Microsoft MVP) on how to make use of Winget in the System Context (which isn't the default option by now).
It got pretty clear instantly that his scripts shall be usable with JumpCloud Commands as well.
In his article, Section 2.2 provides the PS-code to be used to install Winget and section 3 explains how to get apps installed.
Install Winget
#WebClient
$dc = New-Object net.webclient
$dc.UseDefaultCredentials = $true
$dc.Headers.Add("user-agent", "Inter Explorer")
$dc.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
#temp folder
$InstallerFolder = $(Join-Path $env:ProgramData CustomScripts)
if (!(Test-Path $InstallerFolder))
{
New-Item -Path $InstallerFolder -ItemType Directory -Force -Confirm:$false
}
#Check Winget Install
Write-Host "Checking if Winget is installed" -ForegroundColor Yellow
$TestWinget = Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -eq "Microsoft.DesktopAppInstaller"}
If ([Version]$TestWinGet. Version -gt "2022.506.16.0")
{
Write-Host "WinGet is Installed" -ForegroundColor Green
}Else
{
#Download WinGet MSIXBundle
Write-Host "Not installed. Downloading WinGet..."
$WinGetURL = "https://aka.ms/getwinget"
$dc.DownloadFile($WinGetURL, "$InstallerFolder\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
#Install WinGet MSIXBundle
Try {
Write-Host "Installing MSIXBundle for App Installer..."
Add-AppxProvisionedPackage -Online -PackagePath "$InstallerFolder\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense
Write-Host "Installed MSIXBundle for App Installer" -ForegroundColor Green
}
Catch {
Write-Host "Failed to install MSIXBundle for App Installer..." -ForegroundColor Red
}
#Remove WinGet MSIXBundle
#Remove-Item -Path "$InstallerFolder\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue
}
Install Chrome (as an example) with --scope machine:
$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
if ($ResolveWingetPath){
$WingetPath = $ResolveWingetPath[-1].Path
}
$config
Set-Location $wingetpath
.\winget.exe install --exact --id Google.Chrome --silent --accept-package-agreements --accept-source-agreements --scope machine
Note: I gave both scripts a timeout of 600 seconds
11-01-2022 09:40 AM
This is great. I have a similar post and approach to using winget in JumpCloud commands but I didn't know you could install winget via powershell. That is very handy, thanks for sharing!
11-08-2023 08:58 AM
Why do you use this header:
$dc.Headers.Add("user-agent", "Inter Explorer")
$dc.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
Why there is
"Inter Explorer"
Not just 'Internet Explorer'?
Why you do not use just:
(New-Object System.Net.WebClient).DownloadFile($WinGetURL, "$InstallerFolder\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
New to the site? Take a look at these additional resources:
Ready to join us? You can register here.