I have used this post from JumpCloud in the past to get it installed. Copy and paste the code into a Worklet and run the Worklet: https://community.jumpcloud.com/t5/community-scripts/install-winget-in-the-system-context-and-applications-via-winget/m-p/1399
Link is dead. I have been experimenting with using add-appxpackage to install winget and using winget on existing windows 11 computer and not had any success on either.
I moved forward and attempted to use to use a windows 11 computer with winget installed. But all attempts to use winget have failed with winget not recognized. I tried to force the path %userprofile%\AppData\Local\Microsoft\WindowsApps but that was also not successful. I have another deploy product that is able to use winget in powershell to install. Am I missing something?
if (.\winget list --id Microsoft.PowerBI | findstr Available) {
# this will check installed version vs most recent available and if need upgrade if not will not
Write-Host "Upgrading Power BI"
.\winget upgrade --id=Microsoft.PowerBI
}
Evaluation policy
if (.\winget list --id Microsoft.PowerBI | findstr Available) {
Write-Host "Power BI out of date"
exit 1
}
else
{
exit 0
}
{"args":"","response":"[\"0\",null,\".\\\\winget : The term '.\\\\winget' is not recognized as the name of a cmdlet, function, script file, or operable program. \\r\\nCheck the spelling of the name, or if a path was included, verify that the path is correct and try again.\\r\\nAt C:\\\\Program Files (x86)\\\\Automox\\\\execDir3634317923\\\\execcmd4137578730.ps1:73 char:5\\r\\n+ if (.\\\\winget list --id Microsoft.PowerBI | findstr Available) {\\r\\n+ ~~~~~~~~\\r\\n + CategoryInfo : ObjectNotFound: (.\\\\winget:String) [], CommandNotFoundException\\r\\n + FullyQualifiedErrorId : CommandNotFoundException\"]"} Show Less
I have been unable to install winget with automox. I tried add-appxpackage -registerbyfamilyname and with local msixbundle file.
However the more important question is how to use winget from automox. On a windows 11 computer with working winget, every attempt to use winget to install software is failing. Automox cannot find working winget. I tried to specific path to winget with %userprofile%\AppData\Local\Microsoft\WindowsApps, this did not help. Any suggestions?
{"args":"","response":"[\"0\",null,\".\\\\winget : The term '.\\\\winget' is not recognized as the name of a cmdlet, function, script file, or operable program. \\r\\nCheck the spelling of the name, or if a path was included, verify that the path is correct and try again.\\r\\nAt C:\\\\Program Files (x86)\\\\Automox\\\\execDir3634317923\\\\execcmd4137578730.ps1:73 char:5\\r\\n+ if (.\\\\winget list --id Microsoft.PowerBI | findstr Available) {\\r\\n+ ~~~~~~~~\\r\\n + CategoryInfo : ObjectNotFound: (.\\\\winget:String) [], CommandNotFoundException\\r\\n + FullyQualifiedErrorId : CommandNotFoundException\"]"} Show Less
How about this?
# Set the execution policy to allow running scripts (if not already set)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
# Install the winget-install script from the PowerShell Gallery
Install-Script -Name winget-install -Force
# Run the winget-install script to install Winget
winget-install
Everytime I execute a Worklet, I include the absolute path of Winget in a variable:
$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
Where it reads ‘...x64….’ in this example needs to be updated to ‘arm64’ when needed for arm devices.
The Required Software policy works great for the Eval scope so that does not have to be scripted.
I am using this on devices which don’t have it by default (very unusual these days)
#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"
$TestWinget = Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -eq "Microsoft.DesktopAppInstaller"}
If ([Version]$TestWinGet. Version -gt "2022.506.16.0")
{
Write-Host "WinGet is Installed"
}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"
}
Catch {
Write-Host "Failed to install MSIXBundle for App Installer..."
}
#Remove WinGet MSIXBundle
#Remove-Item -Path "$InstallerFolder\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue
}
add or remove commented out lines as needed