Condividi tramite


SDK: Creating DDRs on the site server using the client messaging SDK part 2: creating System DDRs

Last year I posted about functionality in the Configuration Manager client messaging SDK to generate DDRs and provided samples on how to create a DDR for a completely custom agent type: a printer. It's also a common scenario on wanting to generate DDRs to add additional discovery information for regular client systems. It's very similar to do this but with a couple of subtle differences that I will cover here. The main difference is that you need to use an architecture of 'System' (case sensitive) and you need to be careful to make sure your 'Name' matches what's in the database exactly or else you may end up renaming the record and causing confusion.

Here's a simple PowerShell script that demonstrates this:

 # This must be set to match the path to the Configuration Manager 2012 SDK
 $modulePath = 'D:\Program Files (x86)\Microsoft System Center 2012 R2 Configuration Manager SDK\Redistributables\Microsoft.ConfigurationManagement.Messaging.dll'
 
 # Set this to match your machine name
 $name = 'R2311195'
 
 # This must be a name of your special DDR generator
 $agentName = 'MySpecialThirdPartyAgent'
 
 # This should match your site code
 $siteCode = 'R2S'
 
 # 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('Name', [Microsoft.ConfigurationManagement.Messaging.Messages.Server.DdmDiscoveryFlags]::Key -bor [Microsoft.ConfigurationManagement.Messaging.Messages.Server.DdmDiscoveryFlags]::Name, 32, $name)
 $ddr.AddStringProperty('Netbios Name', [Microsoft.ConfigurationManagement.Messaging.Messages.Server.DdmDiscoveryFlags]::Name, 16, $name)
 $ddr.AddIntegerProperty('TestInstallAuto', [Microsoft.ConfigurationManagement.Messaging.Messages.Server.DdmDiscoveryFlags]::None, 0)
 $ddr.AddIntegerProperty('TestInstall', [Microsoft.ConfigurationManagement.Messaging.Messages.Server.DdmDiscoveryFlags]::None, 1)
 $ddr.AddStringProperty('Wow', [Microsoft.ConfigurationManagement.Messaging.Messages.Server.DdmDiscoveryFlags]::None, 32, "Such custom")
 $ddr.SerializeToInbox()

This creates a new DDR and adds it into the inbox. After a few seconds, DDM will process this and those changes should be reflected in the discovery data for the machine: