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.
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']
}
}