11 Apr, 2019

Easily test SCCM WQL queries in powershell

Just a quick post on an SCCM powershell cmdlet that is not referenced well enough on the web for running and testing your SCCM WQL queries:

Invoke-CMWmiQuery (https://docs.microsoft.com/en-us/powershell/module/configurationmanager/invoke-cmwmiquery?view=sccm-ps)

It allows you, without connecting to WMI / without specifying your server name or site code or the namespace that you have to google every time.

This can be used to get some data on your database but also to easily test your query for collections.

$WQL = @”
SELECT app.* FROM SMS_ApplicationLatest AS app
INNER JOIN SMS_CIContentPackage AS con ON app.CI_ID=con.CI_ID
INNER JOIN SMS_DistributionPoint AS srv ON con.PackageID=srv.PackageID
WHERE app.IsHidden = 0
“@

The easy way: Invoke-CMWmiQuery -Query $WQL

The old way: Get-WmiObject -Query $WQL -ComputerName “SCCMSERVER” -Namespace “root\sms\site_PRI”

 

About : philippe

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code