Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

PENDING WinGet - PS detection method

  • Thread starter Thread starter m0rph
  • Start date Start date
  • Replies Replies 5
  • Views Views 5K

m0rph

Member
Messages
18
Reaction score
2
Points
3
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 my environment, I have a script that checks the latest versions of a list of winget applications, then creates/updates a number of MECM collections based on that version, updates PSADT based applications and deployment types (including the mentioned detection script), and spreads installations in time over different collections. Below is my latest version with some improvements. It can find the most recent version of winget.exe and allows 2 methods for determining the latest version (winget of fixed). It now also allows to find the latest version in the application name. For some "weird" applications, this is necessary. SSMS for example is version 18.12.1 today, but appears as 15.0.18424.0 in control panel.

try{
$WingetEXEs = (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe").Path | measure-object -line
$WingetPath = (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe")[$WingetEXEs.Lines - 1].Path
$LatestVersionSource = 'MECM'
$LatestVersion = $null
$CurrentVersion = $null
}
catch{}

if ($LatestVersionSource -eq 'Winget'){
try{
$WingetShow = & $WingetPath show --accept-source-agreements --id 7zip.7zip
foreach ($Show in $WingetShow){
if ($Show -like 'Version: *'){
$VersionLineLatest = $Show
}
}

$LatestVersion = $VersionLineLatest.trim("Version: ")
}
catch{}
}

if ($LatestVersionSource -eq 'MECM'){
$LatestVersion = '22.01'}

try{
$WingetList = & $WingetPath list --Id 7zip.7zip
foreach ($List in $WingetList){
if ($List -like '*7zip.7zip*'){
$VersionLineCurrentId = $List
}
}

if (!($VersionLineCurrentId)){
$WingetList = & $WingetPath list --Name '7-zip'
foreach ($List in $WingetList){
if ($List -like '*7-zip*'){
$VersionLineCurrentName = $List
}
}
}

if ($VersionLineCurrentId){
$VersionLineCurrentId -match "7zip\.7zip (?<content>.*) " | Out-Null
$CurrentVersion = $matches['content'].split(' ')[0]
}

if ($VersionLineCurrentName){
$VersionLineCurrentName -match "} (?<content>.*) " | Out-Null
$VersionLineCurrentNameSplit = $VersionLineCurrentName.Split(" ")
$CurrentVersion = $VersionLineCurrentNameSplit[-1]
}

if (($CurrentVersion -ne $null) -and ($CurrentVersion -ge $LatestVersion)){
write-host 'Installed'
}
}
catch{}
 
These are the applications I deploy and update with this method:

7-zip
Anydesk
Belgium e-ID middleware
Belgium e-ID viewer
Citrix Workspace
Dell Command | Update
Google Chrome
Greenshot
Java 8 Update
Local Administrator Password Solution
Microsoft ASP.NET Core 5
Microsoft ASP.NET Core 6
Microsoft .NET Runtime - 5
Microsoft .NET Runtime - 6
Microsoft Edge
Microsoft SQL Server Management Studio
Microsoft Visual C++ 2005 Redistributable
Microsoft Visual C++ 2005 Redistributable (x64)
Microsoft Visual C++ 2008 Redistributable - x86
Microsoft Visual C++ 2008 Redistributable - x64
Microsoft Visual C++ 2010 x86 Redistributable
Microsoft Visual C++ 2010 x64 Redistributable
Microsoft Visual C++ 2012 Redistributable (x86)
Microsoft Visual C++ 2012 Redistributable (x64)
Microsoft Visual C++ 2013 Redistributable (x86)
Microsoft Visual C++ 2013 Redistributable (x64)
Microsoft Visual C++ 2015-2022 Redistributable (x86)
Microsoft Visual C++ 2015-2022 Redistributable (x64)
Microsoft Windows Desktop Runtime - 5
Microsoft Windows Desktop Runtime - 6
Mozilla Firefox
mRemoteNG
Notepad++
Powershell 7
PuTTY
Screenpresso
TreeSize
VLC
Vmware Horizon Client
Webex
Windows Terminal
WinRAR
WinZip
Wireshark
Zoom
 
Enable this option and check again? This may display if it requires any user acceptance.
Based on the output, you can customize your script in 100% silent mode.
1665417416957.png
 
Enable this option and check again? This may display if it requires any user acceptance.
Based on the output, you can customize your script in 100% silent mode.
View attachment 4809

Thank you, the second version of the detection script (here in post #3) is actually working fine.
I do set the deployments to hidden for all applications. Only our pilot group gets second deployment as "available", so installations stay visible in Software Center / Installation status.
 

Forum statistics

Threads
7,156
Messages
27,932
Members
18,237
Latest member
Causal
Back
Top