0

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
}
3
  • 1
    Those are usually in C:\Program Files\WindowsApps and not the (x86) folder. I would say to change it to that explicitly or check to see why $env:ProgramFiles is expanding to the x86 "Program Files" folder on that particular system. Commented Jun 18, 2024 at 18:11
  • Try $Winget = (Get-Command winget.exe).Source? Commented Jun 18, 2024 at 20:38
  • You do not have permission to read the folder. Try using File Explorer and see if you have access to the folder/files. If you are an admin try replacing the colon 'c:\' with a dollar sign. Commented Oct 14, 2024 at 9:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.