-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset-Appx.ps1 - Winget Company Portal install weird behavior, only showing for user after second run if $removeAppxPackage is null #5
Comments
Thanks for flagging as an issue, I saw this last night too. WinGet certainly does weird stuff as SYSTEM. |
Made an update to the Install-WinGetApp function to rerun the winget install if it was not detected by "$testWinGetInstall = Get-AppXPackage -AllUsers | Where-Object { $_.Name -like $removeApp }". Not sure if this is best way, but it does work.
|
Thanks @Sn00zEZA Update: |
Probably found out why @Sn00zEZA code update didn't solve the problem for me: I think this is the better solution, the SID stays the same no matter the OS localization: |
Ah that would make sense. Will update my script with this also. Thank you for raising this. |
Thanks @theITcloudAdmn and @Sn00zEZA I will proceed with the code mod later today. Appreciate your input here! |
I have tried the script in our environment and it works fine for those who have the old installation on the machine. If you set up a new device, which by default gets the new Company Portal via Winget, the script unfortunately uninstalls the portal directly again. If you run the script again, it is installed again, the next time then removed again. The change of Sn00zEZA does not solve the problem for me. Then, according to the log, it recognizes an existing version that it wants to update, finds no update, claims it was successful, but the portal is not present. I run the script via Live Response Session, it should behave similar to Intune? |
Can you please try version 1.06.27.0 |
Different behavior, same result. If it is started once and it is already present, it is not executable afterwards. If you start the script again, it works and then always in alternation. It is interesting that the script throws an error if it works afterwards. If there is no error at the end, the Company Portal does not work. I copy the message here, but unfortunately it is in German. I start the script via the live response session on the notebook. Errors:
|
Would be super interesting to understand, why sometimes the app gets installed just for the system user in this strange state (check So I ended up with this (not really nice but does the job):
Testing looks promising. Think I'm going to roll this out to production. |
Thanks for the info. I am looking at a regression issue in the new version. I like the idea of exiting with code 1, that makes sense and will retry when delivered as an Intune script (max 3 times)
Why it requires a 2nd retry sometimes still remains a mystery to me
Ben Whitmore
Enterprise Mobility MVP
…________________________________
From: theITcloudAdmn ***@***.***>
Sent: Wednesday, June 28, 2023 8:03:08 AM
To: byteben/MEM ***@***.***>
Cc: Ben Whitmore ***@***.***>; Comment ***@***.***>
Subject: Re: [byteben/MEM] Reset-Appx.ps1 - Winget Company Portal install weird behavior, only showing for user after second run if $removeAppxPackage is null (Issue #5)
Would be super interesting to understand, why sometimes the app gets installed just for the system user in this strange state (check PackageUserInformation)!
So I ended up with this (not really nice but does the job):
1. Adjusted the modification from @Sn00zEZA<https://github.com/Sn00zEZA> sligthly so if the app isn't installed correctly after 2nd try, script will end with exit code 1. Like that, Intune will do another rerun of the script which normaly ends with success.
if ($winGetAppInstallAttempted) {
$testWinGetInstall = Get-AppXPackage -AllUsers | Where-Object { $_.Name -like $removeApp } -ErrorAction Stop
if (($testWinGetInstall.Name -eq $removeApp) -and ($testWinGetInstall.PackageUserInformation.UserSecurityId.Sid -ne "S-1-5-18")) {
Write-Host "Success: The '$($winGetAppName)' app, with Id $($winGetApp), installed succesfully. Check the Winget logs at 'C:\Windows\Temp\WinGet\defaultState' for more information"
Write-LogEntry -logEntry "Success: The '$($winGetAppName)' app, with Id '$($winGetApp)', installed succesfully. Check the Winget logs at 'C:\Windows\Temp\WinGet\defaultState' for more information" -logID $logID
}
else {
Write-Warning -Message "Error: The '$($winGetAppName)' app, with Id '$($winGetApp)', did not install succesfully. Check the Winget logs at 'C:\Windows\Temp\WinGet\defaultState' for more information"
Write-LogEntry -logEntry "Error: The '$($winGetAppName)' app, with Id '$($winGetApp)', did not install succesfully. Check the Winget logs at 'C:\Windows\Temp\WinGet\defaultState' for more information" -logID $logID -severity 3
# Attempt to re-run installer if AppXPackage was not detected in the previous install
Write-Host "Re-running install '$($winGetAppName)', with Id '$($winGetApp)', was not detected after previous attempt"
Write-LogEntry -logEntry "Rerunning install '$($winGetAppName)', with Id '$($winGetApp)', was not detected after previous attempt" -logID $logID
Write-Host ".\winget.exe install --id '$winGetApp' --accept-package-agreements --accept-source-agreements --source $winGetAppSource --scope machine"
Write-LogEntry -logEntry ".\winget.exe install --Id '$winGetApp' --accept-package-agreements --accept-source-agreements --source $winGetAppSource --scope machine" -logID $logID
.\winget.exe install --id $winGetApp --accept-package-agreements --accept-source-agreements --source $winGetAppSource --scope machine
$testWinGetInstall = Get-AppXPackage -AllUsers | Where-Object { $_.Name -like $removeApp } -ErrorAction Stop
if ($testWinGetInstall.Name -eq $removeApp) {
Write-Host "Success: The '$($winGetAppName)' app, with Id $($winGetApp), installed succesfully. Check the Winget logs at 'C:\Windows\Temp\WinGet\defaultState' for more information"
Write-LogEntry -logEntry "Success: The '$($winGetAppName)' app, with Id '$($winGetApp)', installed succesfully. Check the Winget logs at 'C:\Windows\Temp\WinGet\defaultState' for more information" -logID $logID
}
else {
Write-Warning -Message "Error: The '$($winGetAppName)' app, with Id '$($winGetApp)', did not install succesfully. Check the Winget logs at 'C:\Windows\Temp\WinGet\defaultState' for more information"
Write-LogEntry -logEntry "Error: The '$($winGetAppName)' app, with Id '$($winGetApp)', did not install succesfully. Check the Winget logs at 'C:\Windows\Temp\WinGet\defaultState' for more information" -logID $logID -severity 3
Write-Output -Message "Stopped processing the script with error code 1"
Write-LogEntry -logEntry "Stopped processing the script with error code 1" -logID $logID
Set-Location $PSScriptRoot
Exit 1
}
}
}
1. Built a remediation script as addition to detect if the app is correctly installed (as remediation the Reset-Appx.ps1 script is run):
$CheckApp = "Microsoft.CompanyPortal"
Try {
$TestAppxInstall = Get-AppXPackage -AllUsers | Where-Object { $_.Name -like $CheckApp } -ErrorAction Stop
If (($TestAppxInstall.Name -eq $CheckApp) -and ($TestAppxInstall.PackageUserInformation.UserSecurityId.Sid -ne "S-1-5-18")){
Write-Output $TestAppxInstall
Write-Output "Compliant - Found App '$($CheckApp)'"
Exit 0
}
Write-Output $TestAppxInstall
Write-Warning "Not Compliant - App '$($CheckApp)' not found!"
Exit 1
}
Catch {
Write-Output $TestAppxInstall
Write-Warning "Not Compliant - Error processing Script!"
Exit 1
}
Testing looks promising. Think I'm going to roll this out to production.
—
Reply to this email directly, view it on GitHub<#5 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AKSAHIEB5BVNI6MO3MIGLYLXNPJKZANCNFSM6AAAAAAZNCDB4M>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Found the root cause of this. There are 2 possible error conditions after using winget to install the app as system. We can triage both now we understand the issue. Fix coming in v2 of script |
All 3 conditions listed below are fixed in V1.07.03.0 of Reset-Appx.ps1 Condition 1: Condition 2: Condition 3: WinGet will retry 10 times (by default) to install the app successfully and ensure the conditions above are not present. |
Sorry. I used the latest version of the script and i still have to run the second time before company portal app is visible to the user computer |
Picking up strange behavior when $removeAppxPackage is passed. Script will remove Company Portal using functions Remove-AppxPkg and Remove-AppxProvPkg, then successfully install Company Portal via winget, but its not detected by "Get-AppXPackage -AllUsers" in the Install-WinGetApp function. Running the script a second time it is detected successfully and the user will have Company Portal available.
Changing "$winGetTest = .\winget.exe list --id $winGetApp --source $winGetAppSource --accept-source-agreements" to include "--scope machine" shows that the app is indeed present. during both script runs.
Just not sure why it only works if $removeAppxPackage is null.
The text was updated successfully, but these errors were encountered: