I am trying to update 7zip for all computers in our organization using a remediation script in intune. When I run the script locally on my computer, it works fine, but when I run it through intune, on all machines it gives the error:
Get-ChildItem : Cannot find path 'C:\Program Files (x86)\WindowsApps' because it does not exist. At C:\WINDOWS\IMECache\HealthScripts\0f83503b-299b-4809-97a5-62effa1dc8f6_1\detect.ps1:3 char:11 + $Winget = Get-ChildItem -Path (Join-Path -Path (Join-Path -Path $env: ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Program Files (x86)\WindowsApps:String) [Get-ChildItem], ItemNotFoun dException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object. At C:\WINDOWS\IMECache\HealthScripts\0f83503b-299b-4809-97a5-62effa1dc8f6_1\detect.ps1:5 char:8 + if ($(&$winget upgrade) -like "* $app_2upgrade *") { + ~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : BadExpression
The detection script now looks like this:
$app_2upgrade = "7zip.7zip"
$Winget = Get-ChildItem -Path (Join-Path -Path (Join-Path -Path $env:ProgramFiles -ChildPath "WindowsApps") -ChildPath "Microsoft.DesktopAppInstaller*_x64*\winget.exe")
if ($(&$winget upgrade) -like "* $app_2upgrade *") {
Write-Host "Upgrade available for: $app_2upgrade"
exit 1 # upgrade available, remediation needed
}
else {
Write-Host "No Upgrade available"
exit 0 # no upgared, no action needed
}
C:\Program Files\WindowsAppsand not the(x86)folder. I would say to change it to that explicitly or check to see why$env:ProgramFilesis expanding to thex86"Program Files" folder on that particular system.$Winget = (Get-Command winget.exe).Source?