Case of the Empty Properties in ConfigMgr WMI Queries

To improve ConfigMgr performance, by default not all properties are retrieved when running a WMI query. The ConfigMgr PowerShell cmdlets by default retrieve all properties, but have a –Fast option, which gives us the same results as the normal WMI query.

In some cases it’s inconvenient to use the ConfigMgr cmdlets due to requirements of having Configuration Manager Console installed. While it is not to hard to hack a way around this limitation, it still requires a lot of DLLs from Configuration Manager install to make it work.

In this case I wanted to retrieve SDMPackageXML property of SMS_Application class, but normal WMI query returns NULL for this property.

Example code:

$server = "sccm01.testad.local"
$site = "TST"
$session = New-CimSession -ComputerName $server 
$sessionInfo = @{
    CimSession = $session
    NameSpace = "root\SMS\site_$site"
}

$appInfo = Get-CimInstance @sessionInfo -ClassName "SMS_Application" -Filter "LocalizedDisplayName = 'Microsoft Office 97' AND IsLatest = 1"

Result, SDMPackageXML is empty, the same as if –fast option has been used with Get-CMApplication in Powershell.

image

To figure out what was going on I monitored Powershell process with API monitor monitoring System Administration –> Windows Management Instrumentation (WMI)

image

Then I ran two PowerShell commands

Get-CMApplication -Name "Microsoft Office 97"
Get-CMApplication -Name "Micorosft Office 97" -fast

Checking the API monitor log we can see what was different:

Without FAST option

IWbemLocator::ConnectServer ( "\\SCCMDC01.testad.local\root\sms\site_TST", NULL, NULL, "", WBEM_FLAG_CONNECT_USE_MAX_WAIT, "", 0x0000029ef3780d20, 0x000000eb4114e2f8 ) 
IWbemServices::ExecQuery ( "WQL", "SELECT * FROM SMS_Application WHERE LocalizedDisplayName = 'Microsoft Office 97' AND IsLatest = 1", 304, 0x0000029ef377ff20, 0x000000eb3e34def8 )  
IWbemServices::GetObject ( "SMS_Application.CI_ID=16777703", 0, 0x0000029ef3782220, 0x000000eb3e34e0d0, NULL )   

With FAST option

IWbemLocator::ConnectServer ( "\\SCCMDC01.testad.local\root\sms\site_TST", NULL, NULL, "", WBEM_FLAG_CONNECT_USE_MAX_WAIT, "", 0x0000029ef3780d20, 0x000000eb4114e2f8 ) 
IWbemServices::ExecQuery ( "WQL", "SELECT * FROM SMS_Application WHERE LocalizedDisplayName = 'Microsoft Office 97' AND IsLatest = 1", 304, 0x0000029ef377ff20, 0x000000eb3e34def8 )  

We can see without the FAST option, an additional WMI command is sent, GetObject ( “SMS_Application.CI_ID=16777703”)

From this information we can build a working PowerShell command. In this case I used .NET methods because it was what I knew, further investigation needs to be done if there is a more PowerShell-ish way to achieve the same result:

$server = "sccm01.testad.local"
$site = "TST"

$options = New-Object System.Management.ConnectionOptions
# configure connection options as necessary

$scope = New-Object System.Management.ManagementScope("\\$server\root\sms\site_$site",$options)
$scope.Connect()

$options = New-Object System.Management.ObjectGetOptions
# if we don't know CI_ID we need to use our normal WMI query by application name first to find it
$object = New-Object System.Management.ManagementObject($scope,"SMS_Application.CI_ID=16777703",$options)
$object.Get()

We now have the package XML

image

It should be noted that this type of WMI query is quite a bit slower than the original, so should only be used when needed.

About chentiangemalc

specializes in end-user computing technologies. disclaimer 1) use at your own risk. test any solution in your environment. if you do not understand the impact/consequences of what you're doing please stop, and ask advice from somebody who does. 2) views are my own at the time of posting and do not necessarily represent my current view or the view of my employer and family members/relatives. 3) over the years Microsoft/Citrix/VMWare have given me a few free shirts, pens, paper notebooks/etc. despite these gifts i will try to remain unbiased.
This entry was posted in .NET, API Monitor, ConfigMgr, WMI and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s