SDK: Creating DDRs on the site server using the client messaging SDK
Despite its name, the client messaging SDK also has some strictly server side functionality. In its original release with the ConfigMgr 2012 SDK, it could write state messages and status messages directly to the inboxes on the site server. In the SP1 SDK, you can now write DDR messages directly to the site inboxes. This is equivalent to the functionality provided by the old SmsResGenCtl.dll COM library, but is a fully managed solution that doesn’t require any COM registrations or extra libraries.
The old library provided the ability to formulate a completely ad-hoc DDR which could be used to extend resource discovery by being able to add resources into Configuration Manager for objects and their properties that aren’t natively supported. For example, you could inventory your fax machines, printers, chairs (someone actually asked for this once!), and so on.
The class of interest for generating this inventory data is Microsoft.ConfigurationManagement.Messaging.Messages.Server.DiscoveryDataRecordFile.
Here is a code sample on how you may inventory a printer using this API:
DiscoveryDataRecordFile ddrFile = new DiscoveryDataRecordFile("Contoso Printersaurus"); // Agent name is the program that generated the DDR
ddrFile.Architecture = "Printer";
ddrFile.SiteCode = "NP1";
ddrFile.AddStringProperty("Name", DdmDiscoveryFlags.Key | DdmDiscoveryFlags.Name, 32, "MyPrinter001"); // You must have a field defined with Name flag
ddrFile.AddStringProperty("Model", DdmDiscoveryFlags.None, 128, "Contoso PaperMax 2000");
ddrFile.AddStringProperty("Version", DdmDiscoveryFlags.None, 12, "1.0");
ddrFile.AddStringProperty("Location", DdmDiscoveryFlags.None, 128, "Third Floor near break room");
ddrFile.AddDateTimeProperty("DateInstalled", DdmDiscoveryFlags.None, new DateTime(2011, 07, 07));
ddrFile.AddStringPropertyArray("Capabilities", DdmDiscoveryFlags.Array, 32, "Color", "Duplex", "Scanner");
ddrFile.AddIntegerProperty("RAM", DdmDiscoveryFlags.None, 64);
ddrFile.AddIntegerProperty("PagesPrinted", DdmDiscoveryFlags.None, 102);
ddrFile.AddDateTimeProperty("LastPrinted", DdmDiscoveryFlags.None, DateTime.Now);
ddrFile.AddIntegerPropertyArray("PaperLevelPercent", DdmDiscoveryFlags.Array, 100, 75, 0, 0);
ddrFile.AddStringPropertyArray("PaperType", DdmDiscoveryFlags.Array, 32, "Letter", "Letter Extended", "Legal", "A3");
string filename = ddrFile.SerializeToFile("."); // Normally you would use SerializeToInbox
Console.WriteLine("Write DDR to file: {0}", filename);
Pretty simple, right? Basically you define your properties, flags if needed, a maximum length where applicable, and then values. The Architecture field is very important as it will create SMS_R_Architecture resource tables that can be used for collections and query rules. In this sample because the architecture is “Printer”, a SMS_R_Printer class will be created.
The sample here used SerializeToFile to write a file for testing purposes and you’d drop this file into your ddm.box inbox on your site server. A better way to do this is to use the SerializeToInbox method that will automatically drop the file into the appropriate inbox.
Running this program and dropping the .DDR file into ddm.box will create an inventory record (which can be verified via ddm.log).
You can then create a Query (not a Collection since this isn’t a System or User resource) against all instances of SMS_R_Printer. I created one that looks like this:
You can then run this query, and see this resource in the admin console:
Since this data is all stored in SQL and accessible through the provider you can write reports or use other tools to slice and dice this data in interesting ways.
I hope you find this functionality useful!
Comments
- Anonymous
April 23, 2014
Great article, very useful for customization in SCCM 2012.