<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://kdhtechnology.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>KDH Technology</title><link>http://kdhtechnology.com/blogs/</link><description>Software for Administrators by Administrators</description><dc:language>en-US</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Manage DNS with WMI</title><link>http://kdhtechnology.com/blogs/kurt/archive/2007/09/27/manage-dns-with-wmi.aspx</link><pubDate>Thu, 27 Sep 2007 12:33:00 GMT</pubDate><guid isPermaLink="false">5b6c05da-3416-46b3-8993-69c1298b88f2:26</guid><dc:creator>admin</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;One of the biggest complaints I have with Microsoft DNS is it&amp;#39;s Manager.&amp;nbsp; Once you get several thousand DNS entries it can take a long time for the manager to load.&amp;nbsp; It&amp;#39;s even more frustrating when you&amp;#39;re called in the middle of the night and trying to load DNS Manager over a VPN connection.&lt;/p&gt;
&lt;p&gt;Once the DNS Manager snap-in is loaded, the ability to search or filter is non-existent.&lt;/p&gt;
&lt;p&gt;It seems that over 90% of the requests I receive regarding DNS is creating and changing A and CAME records.&amp;nbsp; A simple task that should only take a few seconds, but always seems to take forever.&amp;nbsp; So, I started to look at alternative ways to manage A and CNAME records.&lt;/p&gt;
&lt;p&gt;DNSCMD would allow me to create and modify the records, but have you seen the syntax for dnscmd lately?&amp;nbsp; Of course it could be wrapped in a batch file, but if you ever wanted to migrate to code into Info Path or a web application, it&amp;#39;s not going to work very nice.&lt;/p&gt;
&lt;p&gt;When every I need a system type script written, the first place I look is WMI.&amp;nbsp; Sure enough, DNS is complete exposed via WMI on the DNS Server.&amp;nbsp; The namespace is root\MicrosoftDNS.&lt;/p&gt;
&lt;p&gt;The class MicrosoftDNS_Resource Record has a method of CreateInstanceFromTextRepresentation that will create or A and CNAME records.&lt;/p&gt;
&lt;p&gt;CreateInstanceFromTextRepresentation requires 4 parameters:&amp;nbsp; &lt;em&gt;DNSServerName&lt;/em&gt;, &lt;em&gt;ContainerName&lt;/em&gt;, &lt;em&gt;TextRepresentation&lt;/em&gt;, &lt;em&gt;MicrosoftDNS_ResourceRecordRR&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;DNSServerName is pretty simple.&amp;nbsp; That&amp;#39;s a string with the FQDN&amp;nbsp;of the DNS Server you are creating the record on.&amp;nbsp; (e.g. dns01.kdhtechnology.com)&lt;/p&gt;
&lt;p&gt;ContainerName is a string that contains the domain where you want the record created.&amp;nbsp; (e.g.&amp;nbsp; kdhtechnology.com)&lt;/p&gt;
&lt;p&gt;TextRepresentation is a little a string that contains the record definition.&amp;nbsp; (e.g. foo.kdhtechnology.com IN A 192.168.1.25 )&lt;/p&gt;
&lt;p&gt;MicrosoftDNS_ResourceRecordRR is the return value from the function and it contains the newly created Resource Record.&lt;/p&gt;
&lt;p&gt;So, here is the code to create an A record.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;strServer = “dns01.kdhtechnology.com”&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;strName = “foo”&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;strDomain = “kdhtechnology.com”&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;strIP = “192.168.1.25”&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Set refWMI = GetObject(&amp;quot;:\\&amp;quot; &amp;amp; strServer &amp;amp; &amp;quot;\root\MicrosoftDNS&amp;quot;)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Set objRR = refWMI.Get(&amp;quot;MicrosoftDNS_ResourceRecord&amp;quot;)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Set objMethod = objRR.Methods_(&amp;quot;CreateInstanceFromTextRepresentation&amp;quot;)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;Set objInParm = objMethod.inParameters.SpawnInstance_()&lt;/span&gt;&lt;/p&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;objInParm.TextRepresentation = strName &amp;amp; &amp;quot;.&amp;quot; &amp;amp; strDomain &amp;amp; &amp;quot; IN A &amp;quot; &amp;amp; strIP &lt;/span&gt;&lt;span style="FONT-FAMILY:&amp;#39;Courier New&amp;#39;;"&gt;
&lt;p&gt;objInParm.DnsServerName = strServer &amp;amp; &amp;quot;.&amp;quot; &amp;amp; strDomain &lt;/p&gt;
&lt;p&gt;objInParm.Containername = strDomain &lt;/p&gt;
&lt;p&gt;set objOutParm = objRR.ExecMethod_(&amp;quot;CreateInstanceFromTextRepresentation&amp;quot;, objInParm)&lt;/p&gt;
&lt;p&gt;Set objRR = refWMI.Get(objOutParm.RR)&lt;/p&gt;&lt;/span&gt;
&lt;p&gt;For those who do not want to type in all the code, I have several VBS scripts in the download area.&amp;nbsp; &lt;a href="http://kdhtechnology.com/files/folders/tools/entry28.aspx" target="_blank"&gt;WMI-DNS.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The .VBS files also include the code to create reverse lookups and checks to see if the record exists and gives your the opportunity to delete the record first.&lt;/p&gt;
&lt;p&gt;Kurt&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://kdhtechnology.com/aggbug.aspx?PostID=26" width="1" height="1"&gt;</description><category domain="http://kdhtechnology.com/blogs/kurt/archive/tags/DNS+WMI+VBS+VBScript+Tools/default.aspx">DNS WMI VBS VBScript Tools</category></item></channel></rss>