简体   繁体   中英

SCCM WQL Query - List version of a specific installed application?

I'm struggling to create a WQL query for SCCM as I'm really new and rarely use it in a complex manner.

My goal is to list 3 things : Computer name - Display Name ("Google Chrome") - Display Version (of that Google Chrome entry)

I'm starting with this :

$SiteCode = "XXX"
$SiteServer = "XXX"


$query = @"

select SMS_R_System.Name, SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS.Version
from  SMS_R_System
inner join SMS_G_System_ADD_REMOVE_PROGRAMS
on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = "Google Chrome"

"@


Get-WmiObject -namespace root\sms\site_$SiteCode -computer $SiteServer -query $query

The output is a bit strange to me :

__GENUS                          : 2
__CLASS                          : __GENERIC
__SUPERCLASS                     : 
__DYNASTY                        : __GENERIC
__RELPATH                        : 
__PROPERTY_COUNT                 : 2
__DERIVATION                     : {}
__SERVER                         : XXX
__NAMESPACE                      : root\sms\site_PR1
__PATH                           : 
SMS_G_System_ADD_REMOVE_PROGRAMS : System.Management.ManagementBaseObject
SMS_R_System                     : System.Management.ManagementBaseObject
PSComputerName                   : XXX

What am I missing here? Again i'm really new at this so I must be missing a key part of the logic.

If I remove :

, SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS.Version

The query works and shows me all the computers that have Chrome installed:

__GENUS          : 2
__CLASS          : SMS_R_System
__SUPERCLASS     : SMS_Resource
__DYNASTY        : SMS_BaseClass
__RELPATH        : 
__PROPERTY_COUNT : 1
__DERIVATION     : {SMS_Resource, SMS_BaseClass}
__SERVER         : XXX
__NAMESPACE      : root\sms\site_XXX
__PATH           : 
Name             : PXXX
PSComputerName   : XXX

but I want those 2 properties too, not just the computer name so I can confirm the version numbers.

Much appreciated.

The answer is to simply "expand" the dictionaries like pointed out by @TheIncorrigible.

So here is how I ended up doing it using the Name/Expression method in Select-Object:

$query = @"

select SMS_R_System.Name, SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS.Version
from  SMS_R_System
inner join SMS_G_System_ADD_REMOVE_PROGRAMS
on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = "Google Chrome"

"@


Get-WmiObject -namespace root\sms\site_$SiteCode -computer $SiteServer -query $query | Select-Object @{name='ComputerName';expression={$_.SMS_R_System.Name} }, @{name='DisplayName';expression={$_.SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName} }, @{name='Version';expression={$_.SMS_G_System_ADD_REMOVE_PROGRAMS.Version} }

To expand on my comments in an alternate way to handle the problem at hand:

$wmiParams = @{
    Namespace    = 'root/sms/site_XXX'
    ComputerName = 'XXX'
    Query        = @'
SELECT SMS_R_System.Name, SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS.Version
FROM SMS_R_System
INNER JOIN SMS_G_System_ADD_REMOVE_PROGRAMS
ON SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
WHERE SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = "Google Chrome"
'@
}
$smsResults = Get-WmiObject @wmiParams

foreach ($object in $smsResults) {
    [pscustomobject]@{
        ComputerName = $object['SMS_R_System']['Name']
        DisplayName  = $object['SMS_G_System_ADD_REMOVE_PROGRAMS']['DisplayName']
        Version      = $object['SMS_G_System_ADD_REMOVE_PROGRAMS']['Version']
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM