mike
mike

Reputation: 1

How to write a multi-string (Microsoft) DNS Txt Record usin WMI objects from C#

I am looking for the C# syntax that is required to enable one to use the WMI objects to create a Microsoft DNS text record that consists of multiple strings so that in the end I can have a a full RSA public key in this text record. Iam successful in reading, writing and managing other DNS Records (A,AAAA,CNAME and small txt records) so it is not the basic interaction with the WMI objects.

I have tried multiple combinations of both ManagementBaseObject createdEntry = manager.InvokeMethod("CreateInstanceFromTextRepresentation", inParams2, null) and
manager.InvokeMethod(MicrosoftDnsMethod.CreateInstance, inParams, null) with combinations of (cr lf), spaces, commas and slashes.

I have found that while such a string can be inserted into the DNS Editor on the server, and then sucessfully found using the WMI ManagementObjectSearcher object, the value for this record (which is the provided long string, with escaped double quotes breaking it into multiple strings) this value cannot be used to re-create a similar record (with a different name). As this value can be created in the DNS editor, I suspect that the WMI objects can actually create it, but there appears to be something I am missing.

Upvotes: 0

Views: 428

Answers (1)

mike
mike

Reputation: 1

While the WMI Management Class will not allow a string of strings to be entered, and the same is true for both PowerShell (which is calling WMI) or DNSCMD, one can get around this limitation by storing DNS in zone file rather than in active directory. The zone file is just a text file and it can be edited as a text file. While this does require a reload of the zone, that can be done via WMI calls.

Upvotes: 0

Related Questions