ConfigMgr: Creating System DDR using Client Messaging SDK with SMS Unique Identifier

Within Configuration Manager (ConfigMgr), you can use Discovery Methods to get data about your devices. When a device is successfully discovered it creates a Data Discovery Records (DDRs) file. The DDR then stores all the information about the Device in your ConfigMgr database. DDRs can be useful for adding extra data which you wish to store for a CI, for example, warranty start/end dates.

I’ve been researching ways of adding custom DDRs using the Client Messaging SDK. For this research, I am using ConfigMgr Current Branch. After scavenging the web and reading the SDK documentation; there were some useful articles though most were old and still using legacy methods (VB and ResGen DLLs for example).

I found an excellent post from back in 2014 from Adam Meltzer. Adam shows how to creates a DDR using Powershell (Link Here). The DDR creation method required the resource name of a device. However, I needed to create a DDR using the SMS Unique Identifier instead.

To achieve this, the first step is to download the following:
Microsoft.ConfigurationManagement.Messaging.dll.

Where can I get the Microsoft.ConfigurationManagement.Messaging.dll file?

There are a couple of different ways to download the required DLL.

I would recommend installing the Nuget package. I had issues with the MSI version at first due to the DLL version being old.

Option Version Directory
MSI 5.0.8144.1000 C:\Program Files (x86)\Microsoft System Center 2012 R2 Configuration Manager SDK\Redistributables
Nuget 5.1806.1012.1000 packages\Microsoft.ConfigurationManagement.Messaging.<Version>\lib\net40

 

How to Run the PowerShell DDR command

To run the command, ensure you have imported the DLL and you run on a primary server to access the inbox instances registry key.


#Path to ddl file
$modulePath = 'C:\DLL\Microsoft.ConfigurationManagement.Messaging.dll'
Import-Module $modulePath
# Set this to match your machine unique identifer
$UniqueIdentifier = 'GUID:EABC17A4-XXXX-XXXX-91F5-18F550419E7A'
$PropertyGUID = 'RAFC15AW-3S0M-E38A-N0P-18F550419E7A' #GUID Example
$WarrantyEndDate = (Get-Date).AddYears(4) #Warranty Date Example 
# This must be a name of your special DDR generator
$agentName = 'RafDev'
# This should match your site code
$siteCode = 'RAF'

# Now we generate the DDR object
$ddr = New-Object -typename Microsoft.ConfigurationManagement.Messaging.Messages.Server.DiscoveryDataRecordFile -ArgumentList $agentName
$ddr.SiteCode = $siteCode
$ddr.Architecture = 'System'
$ddr.AddStringProperty('SMS Unique Identifier', [Microsoft.ConfigurationManagement.Messaging.Messages.Server.DdmDiscoveryFlags]::Key -bor [Microsoft.ConfigurationManagement.Messaging.Messages.Server.DdmDiscoveryFlags]::GUID, 64, $UniqueIdentifier)
$ddr.AddStringProperty('WarrantyEndDate', [Microsoft.ConfigurationManagement.Messaging.Messages.Server.DdmDiscoveryFlags]::None, 32, "$WarrantyEndDate")
$ddr.AddStringProperty('RafsGUID', [Microsoft.ConfigurationManagement.Messaging.Messages.Server.DdmDiscoveryFlags]::None, 64, "$PropertyGUID")
$ddr.SerializeToInbox()

 

DDR Warranty Example

Disclaimer

Using the ConfigMgr SDK is for big boys only! do NOT try this on your production environment. Please test in your development environment first.

Thanks,

Raf

Tagged with:

Leave a Reply

Your email address will not be published.