The below script works fine in PS ISE (run as LOCAL SYSTEM). But when used as a detection script, I keep seeing this error:
In-line script returned error output: 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\CCM\SystemTemp\44632d8b-862d-4dd4-8c7b-b768c8c61543.ps1:1 char:29
+ ... getShow = & (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.Des ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Script:
------
$WingetShow = & (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe") show --id Zoom.Zoom
foreach ($Show in $WingetShow){
if ($Show -like 'Version: *'){
$VersionLine = $Show
}
}
$LatestVersion = $VersionLine.trim("Version: ")
$WingetList = (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe") list --id Zoom.Zoom
foreach ($List in $WingetList){
if ($List -like '*Zoom.Zoom*'){
$VersionLine2 = $List
}
}
$VersionLine2 -match "Zoom\.Zoom (?<content>.*) " | Out-Null
$CurrentVersion = $matches['content'].split(' ')[0]
if ($CurrentVersion -eq $LatestVersion){
write-host 'Installed'
}
In-line script returned error output: 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\CCM\SystemTemp\44632d8b-862d-4dd4-8c7b-b768c8c61543.ps1:1 char:29
+ ... getShow = & (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.Des ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Script:
------
$WingetShow = & (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe") show --id Zoom.Zoom
foreach ($Show in $WingetShow){
if ($Show -like 'Version: *'){
$VersionLine = $Show
}
}
$LatestVersion = $VersionLine.trim("Version: ")
$WingetList = (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe") list --id Zoom.Zoom
foreach ($List in $WingetList){
if ($List -like '*Zoom.Zoom*'){
$VersionLine2 = $List
}
}
$VersionLine2 -match "Zoom\.Zoom (?<content>.*) " | Out-Null
$CurrentVersion = $matches['content'].split(' ')[0]
if ($CurrentVersion -eq $LatestVersion){
write-host 'Installed'
}
