What is the SMS Provider and Why Should I Care?

What is the SMS Provider and Why Should I Care?

The SMS Provider is the name given to the WMI Provider which SCCM leverages off to access the information from SCCM. The most common usage is to power the SCCM Console, Resource Manager, and most Console Extensions. It can be used to read and write data into the SCCM environment, and any use who has access to the SCCM Console will have access to the Provider. Traditionally the SMS Provider has been the sphere of the guys who do the crazy awesome extensions for the SCCM environment which we all leverage off to make our jobs easier. So why would we want to access the SMS Provider outside of the SCCM Console? That’s a great question. Let’s just say, for example, you want to get the serial number of a computer from SCCM. Via the SCCM Console you would need to find the Computer in the All Systems collection, then right click and select ‘Start the Resource Explorer’, browse to the PC BIOS Folder and then retrieve the Serial Number. Alternatively, using PowerShell, you can connect to the SMS Provider and can run the following script;

$servername = Get-WmiObject -Namespace root\ccm -Query “select * from SMS_authority” | select CurrentManagementPoint

$Providerdetails = Get-WmiObject -ComputerName $servername.CurrentManagementPoint -Namespace root\sms -Class SMS_Providerlocation | select SiteCode, Machine

$sitecode = $Providerdetails.sitecode

$ProviderServer = $Providerdetails.machine

$compname = $env:COMPUTERNAME

$comps = Get-WmiObject -ComputerName $ProviderServer -Namespace root\SMS\site_$sitecode -query “select * from SMS_R_System full join SMS_G_System_PC_BIOS on SMS_R_System.resourceID = SMS_G_System_PC_BIOS.resourceID where SMS_R_System.name = ‘$compname‘”

$comps.SMS_G_System_PC_BIOS.SerialNumber

Yes, I know, scary looking, right? Let’s break down what the script is actually doing;

$servername = Get-WmiObject -Namespace root\ccm -Query “select * from SMS_authority” | select CurrentManagementPoint So this section is getting the current Management Point of the Computer you are running the script from WMI (so long as the SCCM Client is installed).

$Providerdetails = Get-WmiObject -ComputerName $servername.CurrentManagementPoint -Namespace root\sms -Class SMS_Providerlocation | select SiteCode, Machine

This line returns the details for the SMS Provider from the Management Site Server for the SCCM environment which we are connected to via WMI on the Management Point from where we create Variables for the SiteCode and the name of machine with the SMS Provider is installed (if you have multiple SMS Providers/ Management Points you will have multiple results here) and for the example I have defined the variable $compname as the name of the computer running the script, but this can be changed to the machine you want to find the serial number of.

$sitecode = $Providerdetails.sitecode

$ProviderServer = $Providerdetails.machine

$compname = $env:COMPUTERNAME

The next line is where we actually call the SMS Provider, so we connect to the $Provider Server in the root\sms\site_$sitecode namespace, to execute the query to return all of the System and PC BIOS details for the current computer into the $comps Variable which we then interrogate on the next line to return the Serial Number from the SMS_G_System_PC_BIOS object.

$comps = Get-WmiObject -ComputerName $ProviderServer -Namespace root\SMS\site_$sitecode -query “select * from SMS_R_System full join SMS_G_System_PC_BIOS on SMS_R_System.resourceID = SMS_G_System_PC_BIOS.resourceID where SMS_R_System.name = ‘$compname‘”

$comps.SMS_G_System_PC_BIOS.SerialNumber

So that’s great we now have the serial number a lot quicker than finding it via the Console, but I actually want to get the last logged on user that SCCM has for that machine. Well, all we need to do is change the last line; $comps.SMS_R_System.LastLogonUserName

So we have captured the last logged on user from SCCM, and the Serial number, but what about the Operating System Version? Well we just need to change and re-run the query for comps to something like this; $comps = Get-WmiObject -ComputerName $ProviderServer -Namespace root\SMS\site_$sitecode -query “select * from SMS_R_System full join SMS_G_System_Operating_system on SMS_R_System.resourceID = SMS_G_System_Operating_system.resourceID where SMS_R_System.name = ‘$compname‘” $comps.SMS_G_System_Operating_system.caption 

You will see the only thing I changed between the queries is what SMS_R_System is joined to, to return the caption (where the OS Name is contained if you didn’t know) from the Operating System Table we select the sms_g_system_operating_system.caption object from inside the $comps variable. You can also just type $comps.sms_g_operating_system and it will return all of the Properties for that WMI Class if you don’t know which Property you need. So by now you might be going, “That’s great Steve, you know what variables and tables to be looking for but how the heck am I meant to figure that out?” Well, Kaido has created this awesome Excel Sheet which details all of the Classes for WMI, both Server and Client side which you can download from here and look at the Server WMI Class Properties tab. This will detail all of the default Classes and Properties, if you have extended your hardware inventory to capture even more information it’s really easy to interrogate that information as well, as the Class will appear as SMS_G_System_ and the Properties will match what you added to the Hardware Inventory. To summarize while learning how to use the SMS Provider you might be a little longer to get the information, but in the long term it will save a whole heap of time! Good Luck Steve

Leave a Reply