top of page
Search

(183) Microsoft Intune - Deploying Winget UWP Apps

  • Writer: Mr B SOE way
    Mr B SOE way
  • 1 day ago
  • 3 min read

I have this customer where strangly enough Company Portal and Notepad fail to install properly on their Windows 11 devices, even from the logs I was seeing these:


[Win32App][WinGetApp][WinGetAppDetectionExecutor] Starting detection of app with id: 0a74d8d1-42e1-414a-ade0-5cfec8545c94 and context: SystemContext.
[Win32App][WinGetApp][WinGetOperation] Starting Detection for app with id: 0a74d8d1-42e1-414a-ade0-5cfec8545c94 and package id: 9WZDNCRFJ3PZ.
[Win32App][ReportingManager] Detection state for app with id: 0a74d8d1-42e1-414a-ade0-5cfec8545c94 has been updated. Report delta: {"DetectionErrorOccurred":{"OldValue":false,"NewValue":true}}
[Win32App][ReportingManager] Not sending status update for user with id: 00000000-0000-0000-0000-000000000000 and app: 0a74d8d1-42e1-414a-ade0-5cfec8545c94 because there is not enough data to construct a status report.
[Win32App][WinGetApp][WinGetOperation] Completed Detection for app with id: 0a74d8d1-42e1-414a-ade0-5cfec8545c94 and package id: 9WZDNCRFJ3PZ.
Result: CatalogError
[Win32App][WinGetApp][AppPackageManager] Connect result status: CatalogError (0x0).
[Win32App][WinGetApp][AppPackageManager] Package manager initialized with status: CatalogError (0x0).

Then for Notepad it was:

[Win32App][WinGetApp][WinGetOperation] Completed Detection for app with id: 9974ae35-7901-4244-8422-357b49793131 and package id: 9MSMLRH6LZF3.
Result: CatalogError
 
[Win32App][WinGetApp][WinGetAppDetectionExecutor] Completed detection for app with id: 9974ae35-7901-4244-8422-357b49793131.
WinGet operation result: 
Operation result =  CatalogError
Installed version =  
Reboot required = False
Installer Error code =  (0x0)
Extended error code =  (0x0)
Detection result: 
Action status: Failed
Detection state: NotComputed
Detected version: 
Error code:

Then I thought, does this have something to do with the 'Windows Package Manager' I deployed originally for them, I unassigned that package thinking it may conflict with the latest one and by default Windows 11 has Winget v2.


If you ran in PowerShell with: winget search company, you will notice the source is coming from the msstore.


ree




Similarly if you ran winget search notepad, you will also notice the source is coming from the msstore.

ree



Winget isn't PowerShell friendly after numerous of tests, I managed to get it working. Winget needs to be able to detect it's path back to  "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"


For any Winget custom apps to be installed, Winget must be installed.

ree









On the device under Apps > Installsed apps, you should see this:

ree





For Company Portal:

## Script to install package from Winget in Machine Scope. If unavailable, will fallback to User Scope
## Package is case-sensitive
## Set install parameters if required

#Remove existing Company Portal
Get-AppxPackage -AllUsers -Name Microsoft.CompanyPortal | Remove-AppxPackage -AllUsers

Start-Sleep -Seconds 5

## Set log path
$Path_local = "C:\ProgramData\MrBSOEWay"
Start-Transcript -Path "C:\ProgramData\MrBSOEWay\logs\CompanyPortal.log" -Force -Append

# Resolve winget_exe
$winget_exe = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"
if ($winget_exe.count -gt 1){
        $winget_exe = $winget_exe[-1].Path
}

if (!$winget_exe){Write-Error "Winget not installed"}

## Attempt install using Machine Scope
& $winget_exe install --exact --id 9WZDNCRFJ3PZ --silent --source msstore --accept-package-agreements --accept-source-agreements --scope=machine $param

## Check if app is installed, if not then attempt install using User Scope
$wingetPrg_Existing = & $winget_exe list --id $ProgramName --exact --accept-source-agreements
if ($wingetPrg_Existing -like "*9WZDNCRFJ3PZ*"){
        Write-Host "Found it!"
    }else{
& $winget_exe install --exact --id 9WZDNCRFJ3PZ --silent --source msstore --accept-package-agreements --accept-source-agreements $param
}

Stop-Transcript

$Path_local = "C:\ProgramData\MrBSOEWay"
Start-Transcript -Path "C:\ProgramData\MrBSOEWay\logs\Uninstall-CompanyPortal.log" -Force -Append

# resolve winget_exe
$winget_exe = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"
if ($winget_exe.count -gt 1){
        $winget_exe = $winget_exe[-1].Path
}

if (!$winget_exe){Write-Error "Winget not installed"}

& $winget_exe uninstall --exact --id 9WZDNCRFJ3PZ --silent --accept-source-agreements
Get-AppxPackage -AllUsers -Name Microsoft.CompanyPortal | Remove-AppxPackage -AllUsers

Stop-Transcript
# Detection script for Company Portal UWP app
$path = "C:\Program Files\WindowsApps\Microsoft.CompanyPortal_*_x64__8wekyb3d8bbwe"

if (Test-Path $path) {
    Write-Host "Detected"
    exit 0
} else {
    Write-Host "Not Detected"
    exit 1
}

When packaging the app, you have to make the changes:


Install command line:

%windir%\sysnative\windowspowershell\v1.0\powershell.exe -executionPolicy bypass -windowstyle hidden -file "./Install.ps1" -ProgramName "9WZDNCRFJ3PZ"

Uninstall command line:


%windir%\sysnative\windowspowershell\v1.0\powershell.exe -executionPolicy bypass -windowstyle hidden -file "./Uninstall.ps1" -ProgramName "9WZDNCRFJ3PZ"
ree



















Similarly as Windows Notepad (UWP) via Winget.


## Script to install package from Winget in Machine Scope. If unavailable, will fallback to User Scope
## Package is case-sensitive
## Set install parameters if required

#Remove existing WindowsNotepad
Get-AppxPackage -AllUsers -Name Microsoft.WindowsNotepad | Remove-AppxPackage -AllUsers

Start-Sleep -Seconds 5

## Set log path
$Path_local = "C:\ProgramData\MRBSOEWay"
Start-Transcript -Path "C:\ProgramData\MRBSOEWay\logs\WindowsNotepad.log" -Force -Append

# Resolve winget_exe
$winget_exe = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"
if ($winget_exe.count -gt 1){
        $winget_exe = $winget_exe[-1].Path
}

if (!$winget_exe){Write-Error "Winget not installed"}

## Attempt install using Machine Scope
& $winget_exe install --exact --id 9MSMLRH6LZF3 --silent --source msstore --accept-package-agreements --accept-source-agreements --scope=machine $param

## Check if app is installed, if not then attempt install using User Scope
$wingetPrg_Existing = & $winget_exe list --id $ProgramName --exact --accept-source-agreements
if ($wingetPrg_Existing -like "*9MSMLRH6LZF3*"){
        Write-Host "Found it!"
    }else{
& $winget_exe install --exact --id 9MSMLRH6LZF3 --silent --source msstore --accept-package-agreements --accept-source-agreements $param
}

Stop-Transcript

$Path_local = "C:\ProgramData\MRBSOEWay"
Start-Transcript -Path "C:\ProgramData\MRBSOEWay\logs\Uninstall-WindowsNotepad.log" -Force -Append

# resolve winget_exe
$winget_exe = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"
if ($winget_exe.count -gt 1){
        $winget_exe = $winget_exe[-1].Path
}

if (!$winget_exe){Write-Error "Winget not installed"}

& $winget_exe uninstall --exact --id 9MSMLRH6LZF3 --silent --accept-source-agreements

Stop-Transcript
# Detection script for Notepad UWP app
$path = "C:\Program Files\WindowsApps\Microsoft.WindowsNotepad_*_x64__8wekyb3d8bbwe"

if (Test-Path $path) {
    Write-Host "Detected"
    exit 0
} else {
    Write-Host "Not Detected"
    exit 1
}

Install command line:

%windir%\sysnative\windowspowershell\v1.0\powershell.exe -executionPolicy bypass -windowstyle hidden -file "./Install.ps1" -ProgramName "9MSMLRH6LZF3"

Uninstall command line:

%windir%\sysnative\windowspowershell\v1.0\powershell.exe -executionPolicy bypass -windowstyle hidden -file "./Uninstall.ps1" -ProgramName "9MSMLRH6LZF3"
ree




















Scripts have been uploaded to my github repo.

For Company Portal: Link

For Windows Notepad: Link

 
 
 

Comments


bottom of page