<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Glenn F. Henriksen - Scripting</title>
    <link>http://www.henriksen.no/</link>
    <description>My digital notepad</description>
    <language>en-us</language>
    <copyright>Glenn F. Henriksen</copyright>
    <lastBuildDate>Thu, 11 Jan 2007 08:39:17 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>blog@henriksen.no</managingEditor>
    <webMaster>blog@henriksen.no</webMaster>
    <item>
      <trackback:ping>http://www.henriksen.no/Trackback.aspx?guid=7c5212e1-6093-4a88-87f6-2bab5223a51c</trackback:ping>
      <pingback:server>http://www.henriksen.no/pingback.aspx</pingback:server>
      <pingback:target>http://www.henriksen.no/PermaLink,guid,7c5212e1-6093-4a88-87f6-2bab5223a51c.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.henriksen.no/CommentView,guid,7c5212e1-6093-4a88-87f6-2bab5223a51c.aspx</wfw:comment>
      <wfw:commentRss>http://www.henriksen.no/SyndicationService.asmx/GetEntryCommentsRss?guid=7c5212e1-6093-4a88-87f6-2bab5223a51c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Our primary DNS server changed it's IP yesterday and we had a secondary DNS server
with several domains that needed to have the IP for the master server updated. Windows'
gift and curse is that you don't have a bunch of text files where you can find everything
but manually opening the properties of every domain, removing the previous master
IP, adding a new IP and moving on to the next domain was just not an option. 
</p>
        <p>
That's why we have <a href="http://www.microsoft.com/whdc/system/pnppwr/wmi/default.mspx">Windows
Management Instrumentation</a> (WMI). For an administrator it's the best thing
that's happened since they started slicing bread. Well, not quite, but if you intend
to do some serious administration of Windows servers you'd better look into it. If
you don't like looking through a bunch of documentation for figure out what to do,
use <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&amp;DisplayLang=en">Scriptomatic
2.0</a> like I did yesterday. It will generate a basic script for you that can easily
be modified. 
</p>
        <p>
Now, the main event: a script to update the master server IP for all secondary DNS
zones on a Windows computer.
</p>
        <ol>
          <li class="li1">
            <div class="de1">
              <span class="co1">
                <font color="#808080">' This script updates the
Master server IP for all secondary zones on the</font>
              </span>
            </div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="co1">
                <font color="#808080">' specifed computers.</font>
              </span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <font color="#808080">
              </font> 
</div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="co1">
                <font color="#808080">' Constants for WMI</font>
              </span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="kw1">
                <font color="#b1b100">Const</font>
              </span> wbemFlagReturnWhenComplete
= &amp;H0 
</div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="kw1">
                <font color="#b1b100">Const</font>
              </span> wbemFlagReturnImmediately
= &amp;h10
</div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="kw1">
                <font color="#b1b100">Const</font>
              </span> wbemFlagForwardOnly
= &amp;h20
</div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="kw1">
                <font color="#b1b100">Const</font>
              </span> iDnsSecondary
= <span class="nu0"><font color="#cc66cc">2</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">
              <font color="#cc66cc">
              </font> 
</div>
          </li>
          <li class="li2">
            <div class="de2">
              <font color="#cc66cc">
              </font> 
</div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="co1">
                <font color="#808080">' The array to hold the master
servers </font>
              </span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="co1">
                <font color="#808080">' (there can be multiple
master servers)</font>
              </span>
            </div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="kw1">
                <font color="#b1b100">Dim</font>
              </span> MasterServersArray<span class="br0"><font color="#66cc66">(</font></span><span class="nu0"><font color="#cc66cc">0</font></span><span class="br0"><font color="#66cc66">)</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="co1">
                <font color="#808080">' Add the master servers
to the array. Replace with your own IP</font>
              </span>
            </div>
          </li>
          <li class="li2">
            <div class="de2">MasterServersArray<span class="br0"><font color="#66cc66">(</font></span><span class="nu0"><font color="#cc66cc">0</font></span><span class="br0"><font color="#66cc66">)</font></span> = <span class="st0"><font color="#ff0000">"192.168.2.10"</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">
              <font color="#ff0000">
              </font> 
</div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="co1">
                <font color="#808080">' The address of the old
master server, replace with your own IP</font>
              </span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="co1">
                <font color="#808080">' Used to check the zone
and only update those that need it.</font>
              </span>
            </div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="kw1">
                <font color="#b1b100">Dim</font>
              </span> strOldMasterServer
</div>
          </li>
          <li class="li2">
            <div class="de2">strOldMasterServer = <span class="st0"><font color="#ff0000">"10.0.0.10"</font></span></div>
          </li>
          <li class="li1">
            <font color="#ff0000">
            </font>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="co1">
                <font color="#808080">' The script can do this
on multiple computers, </font>
              </span>
            </div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="co1">
                <font color="#808080">' just add them to the array</font>
              </span>
            </div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="co1">
                <font color="#808080">
                  <span class="kw1">
                    <font color="#b1b100">Dim</font>
                  </span>
                </font>
                <font color="#003300">
                </font>
                <font color="#000000">arrComputers</font>
              </span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">arrComputers = <span class="kw1"><font color="#b1b100">Array</font></span><span class="br0"><font color="#66cc66">(</font></span><span class="st0"><font color="#ff0000">"COMPUTERNAME"</font></span><span class="br0"><font color="#66cc66">)</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="br0">
                <font color="#66cc66">
                </font>
              </span> 
</div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="kw1">
                <font color="#b1b100">Dim </font>
                <font color="#000000">objWMIService</font>
              </span>
            </div>
          </li>
          <li class="li2">
            <span class="kw1">
              <font color="#b1b100">Dim </font>
              <font color="#000000">colItems</font>
            </span>
          </li>
          <li class="li2">
            <span class="kw1">
              <div class="de2">
                <span class="kw1">
                  <font color="#b1b100">Dim </font>
                  <font color="#000000">objItem</font>
                </span>
              </div>
            </span>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="kw1">
                <font color="#b1b100">
                </font>
              </span> 
</div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="kw1">
                <font color="#b1b100">For</font>
              </span> Each strComputer
In arrComputers
</div>
          </li>
          <li class="li1">
            <div class="de1">        WScript.<span class="me1"><font color="#66cc66">Echo</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">        WScript.<span class="me1"><font color="#66cc66">Echo</font></span><span class="st0"><font color="#ff0000">"=========================================="</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">        WScript.<span class="me1"><font color="#66cc66">Echo</font></span><span class="st0"><font color="#ff0000">"Computer:
"</font></span> &amp; strComputer
</div>
          </li>
          <li class="li2">
            <div class="de2">        WScript.<span class="me1"><font color="#66cc66">Echo</font></span><span class="st0"><font color="#ff0000">"=========================================="</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">        
</div>
          </li>
          <li class="li2">
            <div class="de2">        WScript.<span class="me1"><font color="#66cc66">Echo</font></span><span class="st0"><font color="#ff0000">"Fetching
zones..."</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">        <span class="co1"><font color="#808080">'
Connect to the DNS WMI interface on the current computer</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">        <span class="kw1"><font color="#b1b100">Set</font></span> objWMIService
= <span class="kw1"><font color="#b1b100">GetObject</font></span><span class="br0"><font color="#66cc66">(</font></span><span class="st0"><font color="#ff0000">"winmgmts:\\"</font></span> &amp;
strComputer _
</div>
          </li>
          <li class="li2">
            <div class="de2">                &amp; <span class="st0"><font color="#ff0000">"\root\MicrosoftDNS"</font></span><span class="br0"><font color="#66cc66">)</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">
              <font color="#66cc66">
              </font> 
</div>
          </li>
          <li class="li2">
            <div class="de2">        <span class="co1"><font color="#808080">'
Get all zones from the DNS server. We use wbemFlagReturnWhenComplete </font></span></div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="co1">
                <font color="#808080">
                  <font color="#003300">       
' </font>
                </font>
                <font color="#808080">to make sure the call completes before returning.
If not we often get </font>
              </span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">        <span class="co1"><font color="#808080">'
errors when looping through the returned collection. If you only want  </font></span></div>
          </li>
          <li class="li2">
            <div class="de2">        <span class="co1"><font color="#808080">'
some zones to be updated you can filter your query just like any SQL query.</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">        <span class="kw1"><font color="#b1b100">Set</font></span> colItems
= objWMIService.<font color="#66cc66"><span class="me1">ExecQuery</span><span class="br0">(</span></font><span class="st0"><font color="#ff0000">"SELECT
* FROM MicrosoftDNS_Zone"</font></span>, _<span class="st0"><font color="#ff0000"></font></span></div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="st0">
                <font color="#ff0000">
                  <font color="#003300">                </font>"WQL"</font>
              </span>,
wbemFlagReturnWhenComplete + wbemFlagForwardOnly<span class="br0"><font color="#66cc66">)</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">        WScript.<span class="me1"><font color="#66cc66">Echo</font></span><span class="st0"><font color="#ff0000">"Retrieved
zones."</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">
              <font color="#ff0000">
              </font> 
</div>
          </li>
          <li class="li2">
            <div class="de2">        <span class="co1"><font color="#808080">'
Used to hold a return object.</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">        <span class="kw1"><font color="#b1b100">dim</font></span> objTmp
</div>
          </li>
          <li class="li2">
            <div class="de2"> 
</div>
          </li>
          <li class="li1">
            <div class="de1">        <span class="kw1"><font color="#b1b100">For</font></span> Each
objItem In colItems
</div>
          </li>
          <li class="li2">
            <div class="de2">          <span class="co1"><font color="#808080">'
Only secondary zones have master servers</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">          <span class="kw1"><font color="#b1b100">if</font></span> objItem.<span class="me1"><font color="#66cc66">ZoneType</font></span> =
iDnsSecondary <span class="kw1"><font color="#b1b100">then</font></span>   
  
</div>
          </li>
          <li class="li2">
            <div class="de2">                <span class="co1"><font color="#808080">'
Get the current master IPs  </font></span></div>
          </li>
          <li class="li1">
            <div class="de1">                   
    strMastersIPAddressesArray = Join<span class="br0"><font color="#66cc66">(</font></span>objItem.<span class="me1"><font color="#66cc66">MastersIPAddressesArray</font></span>, <span class="st0"><font color="#ff0000">","</font></span><span class="br0"><font color="#66cc66">)</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">                   
    
</div>
          </li>
          <li class="li1">
            <div class="de1">                   
    <span class="co1"><font color="#808080">' Some information </font></span></div>
          </li>
          <li class="li2">
            <div class="de2">                   
    WScript.<span class="me1"><font color="#66cc66">Echo</font></span><span class="st0"><font color="#ff0000">"Name:
"</font></span> &amp; objItem.<span class="kw1"><font color="#b1b100">Name</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">                   
    WScript.<span class="me1"><font color="#66cc66">Echo</font></span><span class="st0"><font color="#ff0000">"MastersIPAddressesArray:
"</font></span> &amp; strMastersIPAddressesArray
</div>
          </li>
          <li class="li2">
            <div class="de2"> 
</div>
          </li>
          <li class="li1">
            <div class="de1">                   
    <span class="co1"><font color="#808080">' We'll only do this in the
zones with the old master server</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">                   
    <span class="co1"><font color="#808080">' No need to update zones that
don't need it.</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">                   
    <span class="kw1"><font color="#b1b100">if</font></span> strMastersIPAddressesArray
= strOldMasterServer <span class="kw1"><font color="#b1b100">then</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">                          <span class="co1"><font color="#808080">'
ResetMasterIpArray is a function on the WMI object </font></span></div>
          </li>
          <li class="li1">
            <div class="de1">                          '<span class="co1"><font color="#808080"> that
replacesthe current array of Master IPs. </font></span></div>
          </li>
          <li class="li2">
            <div class="de2">                          <span class="co1"><font color="#808080">'
objTemp receives a refrence to the updated zone. </font></span></div>
          </li>
          <li class="li1">
            <div class="de1">                   
      objItem.<span class="me1"><font color="#66cc66">ResetMasterIpArray</font></span> MasterServersArray,
objTemp
</div>
          </li>
          <li class="li2">
            <div class="de2">                   
      <span class="co1"><font color="#808080">' We don't need
it so we set it to nothing </font></span></div>
          </li>
          <li class="li2">
            <div class="de2">
              <span class="co1">
                <font color="#808080">
                  <font color="#003300">                     </font>
                  <font color="#808080">    
' immediatly</font> to save memory</font>
              </span>
            </div>
          </li>
          <li class="li1">
            <div class="de1">                   
      <span class="kw1"><font color="#b1b100">set</font></span> objTemp
= <span class="kw1"><font color="#b1b100">nothing</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">                   
      WScript.<span class="me1"><font color="#66cc66">Echo</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">                   
    <span class="kw1"><font color="#b1b100">end</font></span><span class="kw1"><font color="#b1b100">If</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">                   
    <span class="co1"><font color="#808080">' Let's just make the secondary
zone refresh from </font></span></div>
          </li>
          <li class="li1">
            <div class="de1">                   
    <span class="co1"><font color="#808080">' the master server while we're
at it</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">                   
    objItem.<font color="#66cc66"><span class="me1">ForceRefreshOfSecondaryZoneFromMaster</span><span class="br0">(</span><span class="br0">)</span></font></div>
          </li>
          <li class="li1">
            <div class="de1">          <span class="kw1"><font color="#b1b100">end</font></span><span class="kw1"><font color="#b1b100">if</font></span></div>
          </li>
          <li class="li2">
            <div class="de2">        <span class="kw1"><font color="#b1b100">Next</font></span></div>
          </li>
          <li class="li1">
            <div class="de1">
              <span class="kw1">
                <font color="#b1b100">Next</font>
              </span>
            </div>
          </li>
        </ol>
        <a href="http://www.henriksen.no/content/binary/UpdateMasterServerIP.vbs">UpdateMasterServerIP.vbs
(2,82 KB)</a>
        <img width="0" height="0" src="http://www.henriksen.no/aggbug.ashx?id=7c5212e1-6093-4a88-87f6-2bab5223a51c" />
      </body>
      <title>Using VBScript and WMI to change master IP on secondary zone</title>
      <guid isPermaLink="false">http://www.henriksen.no/PermaLink,guid,7c5212e1-6093-4a88-87f6-2bab5223a51c.aspx</guid>
      <link>http://www.henriksen.no/2007/01/11/UsingVBScriptAndWMIToChangeMasterIPOnSecondaryZone.aspx</link>
      <pubDate>Thu, 11 Jan 2007 08:39:17 GMT</pubDate>
      <description>&lt;p&gt;
Our primary DNS server changed it's IP yesterday and we had a secondary DNS server
with several domains that needed to have the IP for the master server updated. Windows'
gift and curse is that you don't have a bunch of text files where you can find everything
but manually opening the properties of every domain, removing the previous master
IP, adding a new IP and moving on to the next domain was just not an option. 
&lt;/p&gt;
&lt;p&gt;
That's why we have &lt;a href="http://www.microsoft.com/whdc/system/pnppwr/wmi/default.mspx"&gt;Windows
Management Instrumentation&lt;/a&gt;&amp;nbsp;(WMI). For an administrator it's the best thing
that's happened since they started slicing bread. Well, not quite, but if you intend
to do some serious administration of Windows servers you'd better look into it. If
you don't like looking through a bunch of documentation for figure out what to do,
use &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&amp;amp;DisplayLang=en"&gt;Scriptomatic
2.0&lt;/a&gt; like I did yesterday. It will generate a basic script for you that can easily
be modified. 
&lt;/p&gt;
&lt;p&gt;
Now, the main event: a script to update the master server IP for all secondary DNS
zones on a Windows computer.
&lt;/p&gt;
&lt;ol&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;' This script updates the Master
server IP for all secondary zones on the&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;' specifed computers.&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;font color=#808080&gt;&lt;/font&gt;&amp;nbsp;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;' Constants for WMI&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Const&lt;/font&gt;&lt;/span&gt; wbemFlagReturnWhenComplete
= &amp;amp;H0 
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Const&lt;/font&gt;&lt;/span&gt; wbemFlagReturnImmediately
= &amp;amp;h10
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Const&lt;/font&gt;&lt;/span&gt; wbemFlagForwardOnly
= &amp;amp;h20
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Const&lt;/font&gt;&lt;/span&gt; iDnsSecondary
= &lt;span class=nu0&gt;&lt;font color=#cc66cc&gt;2&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;font color=#cc66cc&gt;&lt;/font&gt;&amp;nbsp;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;font color=#cc66cc&gt;&lt;/font&gt;&amp;nbsp;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;' The array to hold the master
servers &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;' (there can be multiple master
servers)&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Dim&lt;/font&gt;&lt;/span&gt; MasterServersArray&lt;span class=br0&gt;&lt;font color=#66cc66&gt;(&lt;/font&gt;&lt;/span&gt;&lt;span class=nu0&gt;&lt;font color=#cc66cc&gt;0&lt;/font&gt;&lt;/span&gt;&lt;span class=br0&gt;&lt;font color=#66cc66&gt;)&lt;/font&gt;&lt;/span&gt; 
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;' Add the master servers to the
array. Replace with your own IP&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;MasterServersArray&lt;span class=br0&gt;&lt;font color=#66cc66&gt;(&lt;/font&gt;&lt;/span&gt;&lt;span class=nu0&gt;&lt;font color=#cc66cc&gt;0&lt;/font&gt;&lt;/span&gt;&lt;span class=br0&gt;&lt;font color=#66cc66&gt;)&lt;/font&gt;&lt;/span&gt; = &lt;span class=st0&gt;&lt;font color=#ff0000&gt;"192.168.2.10"&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;font color=#ff0000&gt;&lt;/font&gt;&amp;nbsp;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;' The address of the old master
server, replace with your own IP&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;' Used to check the zone and only
update those that need it.&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Dim&lt;/font&gt;&lt;/span&gt; strOldMasterServer
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;strOldMasterServer&amp;nbsp;= &lt;span class=st0&gt;&lt;font color=#ff0000&gt;"10.0.0.10"&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;font color=#ff0000&gt;&lt;/font&gt; 
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;' The script can do this on multiple
computers, &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;' just add them to the array&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Dim&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font color=#003300&gt; &lt;/font&gt;&lt;font color=#000000&gt;arrComputers&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;arrComputers = &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Array&lt;/font&gt;&lt;/span&gt;&lt;span class=br0&gt;&lt;font color=#66cc66&gt;(&lt;/font&gt;&lt;/span&gt;&lt;span class=st0&gt;&lt;font color=#ff0000&gt;"COMPUTERNAME"&lt;/font&gt;&lt;/span&gt;&lt;span class=br0&gt;&lt;font color=#66cc66&gt;)&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;span class=br0&gt;&lt;font color=#66cc66&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Dim &lt;/font&gt;&lt;font color=#000000&gt;objWMIService&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Dim &lt;/font&gt;&lt;font color=#000000&gt;colItems&lt;/font&gt;&lt;/span&gt; 
&lt;li class=li2&gt;
&lt;span class=kw1&gt; 
&lt;div class=de2&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Dim &lt;/font&gt;&lt;font color=#000000&gt;objItem&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/span&gt; 
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;For&lt;/font&gt;&lt;/span&gt; Each strComputer
In arrComputers
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WScript.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;Echo&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WScript.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;Echo&lt;/font&gt;&lt;/span&gt; &lt;span class=st0&gt;&lt;font color=#ff0000&gt;"=========================================="&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WScript.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;Echo&lt;/font&gt;&lt;/span&gt; &lt;span class=st0&gt;&lt;font color=#ff0000&gt;"Computer:
"&lt;/font&gt;&lt;/span&gt; &amp;amp; strComputer
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WScript.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;Echo&lt;/font&gt;&lt;/span&gt; &lt;span class=st0&gt;&lt;font color=#ff0000&gt;"=========================================="&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WScript.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;Echo&lt;/font&gt;&lt;/span&gt; &lt;span class=st0&gt;&lt;font color=#ff0000&gt;"Fetching
zones..."&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;' Connect
to the DNS WMI interface on the current computer&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Set&lt;/font&gt;&lt;/span&gt; objWMIService
= &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;GetObject&lt;/font&gt;&lt;/span&gt;&lt;span class=br0&gt;&lt;font color=#66cc66&gt;(&lt;/font&gt;&lt;/span&gt;&lt;span class=st0&gt;&lt;font color=#ff0000&gt;"winmgmts:\\"&lt;/font&gt;&lt;/span&gt; &amp;amp;
strComputer _
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;amp; &lt;span class=st0&gt;&lt;font color=#ff0000&gt;"\root\MicrosoftDNS"&lt;/font&gt;&lt;/span&gt;&lt;span class=br0&gt;&lt;font color=#66cc66&gt;)&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;font color=#66cc66&gt;&lt;/font&gt;&amp;nbsp;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;' Get
all zones from the DNS server. We use wbemFlagReturnWhenComplete &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;&lt;font color=#003300&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
' &lt;/font&gt;&lt;/font&gt;&lt;font color=#808080&gt;to make sure the call completes before returning.
If not we often get &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;' errors
when looping through the returned collection. If you only want&amp;nbsp; &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;' some
zones to be updated you can filter your query just like any SQL query.&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Set&lt;/font&gt;&lt;/span&gt; colItems
= objWMIService.&lt;font color=#66cc66&gt;&lt;span class=me1&gt;ExecQuery&lt;/span&gt;&lt;span class=br0&gt;(&lt;/span&gt;&lt;/font&gt;&lt;span class=st0&gt;&lt;font color=#ff0000&gt;"SELECT
* FROM MicrosoftDNS_Zone"&lt;/font&gt;&lt;/span&gt;, _&lt;span class=st0&gt;&lt;font color=#ff0000&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=st0&gt;&lt;font color=#ff0000&gt;&lt;font color=#003300&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;"WQL"&lt;/font&gt;&lt;/span&gt;,
wbemFlagReturnWhenComplete + wbemFlagForwardOnly&lt;span class=br0&gt;&lt;font color=#66cc66&gt;)&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WScript.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;Echo&lt;/font&gt;&lt;/span&gt; &lt;span class=st0&gt;&lt;font color=#ff0000&gt;"Retrieved
zones."&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;font color=#ff0000&gt;&lt;/font&gt;&amp;nbsp;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;' Used
to hold a return object.&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;dim&lt;/font&gt;&lt;/span&gt; objTmp
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;For&lt;/font&gt;&lt;/span&gt; Each
objItem In colItems
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span class=co1&gt;&lt;font color=#808080&gt;'
Only secondary zones have master servers&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;if&lt;/font&gt;&lt;/span&gt; objItem.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;ZoneType&lt;/font&gt;&lt;/span&gt; =
iDnsSecondary &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;then&lt;/font&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp;
&amp;nbsp; 
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;'
Get the current master IPs&amp;nbsp; &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; strMastersIPAddressesArray = Join&lt;span class=br0&gt;&lt;font color=#66cc66&gt;(&lt;/font&gt;&lt;/span&gt;objItem.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;MastersIPAddressesArray&lt;/font&gt;&lt;/span&gt;, &lt;span class=st0&gt;&lt;font color=#ff0000&gt;","&lt;/font&gt;&lt;/span&gt;&lt;span class=br0&gt;&lt;font color=#66cc66&gt;)&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; 
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;' Some information &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; WScript.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;Echo&lt;/font&gt;&lt;/span&gt; &lt;span class=st0&gt;&lt;font color=#ff0000&gt;"Name:
"&lt;/font&gt;&lt;/span&gt; &amp;amp; objItem.&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Name&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; WScript.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;Echo&lt;/font&gt;&lt;/span&gt; &lt;span class=st0&gt;&lt;font color=#ff0000&gt;"MastersIPAddressesArray:
"&lt;/font&gt;&lt;/span&gt; &amp;amp; strMastersIPAddressesArray
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;' We'll only do this in the zones
with the old master server&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;' No need to update zones that don't
need it.&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;if&lt;/font&gt;&lt;/span&gt; strMastersIPAddressesArray
= strOldMasterServer &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;then&lt;/font&gt;&lt;/span&gt; 
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=co1&gt;&lt;font color=#808080&gt;'
ResetMasterIpArray is a function on the WMI object &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&lt;span class=co1&gt;&lt;font color=#808080&gt; that
replacesthe current array of Master IPs. &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;'
objTemp receives a refrence to the updated zone. &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;objItem.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;ResetMasterIpArray&lt;/font&gt;&lt;/span&gt; MasterServersArray,
objTemp
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span class=co1&gt;&lt;font color=#808080&gt;' We don't need it so
we set it to nothing &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&lt;span class=co1&gt;&lt;font color=#808080&gt;&lt;font color=#003300&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color=#808080&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
' immediatly&lt;/font&gt; to save memory&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;set&lt;/font&gt;&lt;/span&gt; objTemp
= &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;nothing&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;WScript.&lt;span class=me1&gt;&lt;font color=#66cc66&gt;Echo&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;end&lt;/font&gt;&lt;/span&gt; &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;If&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;' Let's just make the secondary
zone refresh from &lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &lt;span class=co1&gt;&lt;font color=#808080&gt;' the master server while we're
at it&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; objItem.&lt;font color=#66cc66&gt;&lt;span class=me1&gt;ForceRefreshOfSecondaryZoneFromMaster&lt;/span&gt;&lt;span class=br0&gt;(&lt;/span&gt;&lt;span class=br0&gt;)&lt;/span&gt;&lt;/font&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;end&lt;/font&gt;&lt;/span&gt; &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;if&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li2&gt;
&lt;div class=de2&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Next&lt;/font&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;li class=li1&gt;
&lt;div class=de1&gt;&lt;span class=kw1&gt;&lt;font color=#b1b100&gt;Next&lt;/font&gt;&lt;/span&gt; 
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;a href="http://www.henriksen.no/content/binary/UpdateMasterServerIP.vbs"&gt;UpdateMasterServerIP.vbs
(2,82 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://www.henriksen.no/aggbug.ashx?id=7c5212e1-6093-4a88-87f6-2bab5223a51c" /&gt;</description>
      <comments>http://www.henriksen.no/CommentView,guid,7c5212e1-6093-4a88-87f6-2bab5223a51c.aspx</comments>
      <category>Administration</category>
      <category>Scripting</category>
    </item>
    <item>
      <trackback:ping>http://www.henriksen.no/Trackback.aspx?guid=db4a6888-e713-46d9-9011-daaee138ece5</trackback:ping>
      <pingback:server>http://www.henriksen.no/pingback.aspx</pingback:server>
      <pingback:target>http://www.henriksen.no/PermaLink,guid,db4a6888-e713-46d9-9011-daaee138ece5.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.henriksen.no/CommentView,guid,db4a6888-e713-46d9-9011-daaee138ece5.aspx</wfw:comment>
      <wfw:commentRss>http://www.henriksen.no/SyndicationService.asmx/GetEntryCommentsRss?guid=db4a6888-e713-46d9-9011-daaee138ece5</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A somewhat akward title, but I had a hard time finding a better one :)
</p>
        <p>
We have a <em>projects</em> folder. In that folder there is one folder for each
project and in each project folder there is a <em>documents</em> folder (among many
others). Now, I needed to find the size of each documents folder for each project
and ignore the other folders (don't ask me why).
</p>
        <p>
Seeing as there are a few hundred projects and each documents folder can contain from
five to several thousand files I did not want to check each folder. Since the other
folders are even larger, listing the size of everything and take out what I did
not need would increase the time to create the listing. 
</p>
        <p>
So I created a PowerShell script. Was that the fastest way to do it? Probably not, but
I'll have to do this again someday and then I'll save lots of time. Besides, it didn't
take all that long to create.
</p>
        <pre>$hashTbl=@{};<br />
Get-ChildItem | where-object {$_.Mode -eq "d----"} | `<br />
 foreach-object  { `<br />
   $_.Name;`<br />
  $hashTbl[$_] = ( get-childitem($_.Name + "\documents")`<br />
-recurse -force| `<br />
   measure-object length -sum )<br />
  };<br />
$output = ($hashTbl.psbase.keys |`<br />
 foreach `<br />
  {"Name,Size,File count"} `<br />
  { $_.Name + "," + $hashTbl[$_].Sum + ","`<br />
+ $hashTbl[$_].Count } `<br />
 );<br />
New-Item c:\temp\DirectorySize.csv -type file -force | out-null;<br />
Add-Content c:\temp\DirectorySize.csv  $output; 
<br />
import-csv c:\temp\DirectorySize.csv;</pre>
        <p>
Since some might wonder what the heck I'm doing here (like myself, six months from
now) I thought I'd go through it line by line.
</p>
        <p>
Instansiate an empty hash table
</p>
        <pre>$hashTbl=@{};</pre>
        <p>
Get a list of all children in the current directory and use where-object to get only
the objects that have the directory attibute i.e. just directories and not files.
</p>
        <pre>Get-ChildItem | where-object {$_.Mode -eq "d----"} | `</pre>
        <p>
The result from here is piped into a foreach-object that will do an operation for
each object.
</p>
        <pre> foreach-object  { `</pre>
        <p>
In this operation I display the Name of the folder. This will be outputted while the
script is running, giving me feedback on progress. The ; seperates commands.
</p>
        <pre>   $_.Name;`</pre>
        <p>
The next command might need a bit more explaining.
</p>
        <pre>  $hashTbl[$_] = ( get-childitem($_.Name + "\documents")`<br />
-recurse -force| `<br />
   measure-object length -sum )</pre>
        <p>
From the inside and out: First we use get-childitem for the documents folder. $_ is
an auto-variable from the foreach and contains the current object in the loop. $_.Name
is the name of that folder. Add "\documents" to that to look at the sub-folder I want.
-recurse gets the children of all sub folders and -force includes hidden files.
</p>
        <pre>get-childitem($_.Name + "\documents") -recurse -force </pre>
        <p>
Then we pipe that into measure-object and tells it to sum the length property of all
the items returned from get-childitem.
</p>
        <pre>get-childitem($_.Name + "\documents") -recurse -force| `<br />
   measure-object length -sum )</pre>
        <p>
That creates a GenericMeasureInfo object that I put into the hashtable for later. 
</p>
        <pre>$hashTbl[$_] = ( get-childitem($_.Name + "\documents")`<br />
-recurse -force| `<br />
   measure-object length -sum )</pre>
        <p>
This loops though all the keys in the hashtable and outputs a string with the values
comma-separated. The {"Name,Size,File count"} is the <em>before</em> statement in
the foreach that executes before the loop, outputting the headers for my comma-separated
list. The ( ) around everything makes it a list that I can save in $output.
</p>
        <pre>$output = ($hashTbl.psbase.keys |`<br />
 foreach `<br />
  {"Name,Size,File count"} `<br />
  { $_.Name + "," + $hashTbl[$_].Sum + ","`<br />
+ $hashTbl[$_].Count } `<br />
 );</pre>
        <p>
Create a new file, overwriting any old file. Output is supressed.
</p>
        <pre>New-Item c:\temp\DirectorySize.csv -type file -force | out-null;</pre>
        <p>
Add the comma-separated list to the file.
</p>
        <pre>Add-Content c:\temp\DirectorySize.csv  $output; </pre>
        <p>
Read it and display it for information purposes only.
</p>
        <pre>import-csv c:\temp\DirectorySize.csv;</pre>
        <p>
There, all done. Any questions?
</p>
        <a href="http://www.henriksen.no/content/binary/subSubDirSize.ps1">subSubDirSize.ps1
(,51 KB)</a>
        <img width="0" height="0" src="http://www.henriksen.no/aggbug.ashx?id=db4a6888-e713-46d9-9011-daaee138ece5" />
      </body>
      <title>Using Powershell to find the size of sub-subfolders</title>
      <guid isPermaLink="false">http://www.henriksen.no/PermaLink,guid,db4a6888-e713-46d9-9011-daaee138ece5.aspx</guid>
      <link>http://www.henriksen.no/2007/01/05/UsingPowershellToFindTheSizeOfSubsubfolders.aspx</link>
      <pubDate>Fri, 05 Jan 2007 14:00:02 GMT</pubDate>
      <description>&lt;p&gt;
A somewhat akward title, but I had a hard time finding a better one :)
&lt;/p&gt;
&lt;p&gt;
We have a&amp;nbsp;&lt;em&gt;projects&lt;/em&gt; folder. In that folder there is one folder for each
project and in each project folder there is a &lt;em&gt;documents&lt;/em&gt; folder (among many
others). Now, I needed to find the size of each documents folder for each project
and ignore the other folders (don't ask me why).
&lt;/p&gt;
&lt;p&gt;
Seeing as there are a few hundred projects and each documents folder can contain from
five to several thousand files I did not want to check each folder. Since the other
folders are even larger,&amp;nbsp;listing the size of everything and take out what I did
not need would increase the time to create the listing. 
&lt;/p&gt;
&lt;p&gt;
So I created a PowerShell script. Was that the fastest way to do it? Probably not,&amp;nbsp;but
I'll have to do this again someday and then I'll save lots of time. Besides, it didn't
take all that long to create.
&lt;/p&gt;
&lt;pre&gt;$hashTbl=@{};&lt;br&gt;
Get-ChildItem | where-object {$_.Mode -eq "d----"} | `&lt;br&gt;
&amp;nbsp;foreach-object&amp;nbsp; { `&lt;br&gt;
&amp;nbsp;&amp;nbsp; $_.Name;`&lt;br&gt;
&amp;nbsp;&amp;nbsp;$hashTbl[$_] = ( get-childitem($_.Name + "\documents")`&lt;br&gt;
-recurse -force| `&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;measure-object length -sum )&lt;br&gt;
&amp;nbsp; };&lt;br&gt;
$output = ($hashTbl.psbase.keys |`&lt;br&gt;
&amp;nbsp;foreach `&lt;br&gt;
&amp;nbsp;&amp;nbsp;{"Name,Size,File count"} `&lt;br&gt;
&amp;nbsp;&amp;nbsp;{ $_.Name + "," + $hashTbl[$_].Sum + ","`&lt;br&gt;
+ $hashTbl[$_].Count } `&lt;br&gt;
&amp;nbsp;);&lt;br&gt;
New-Item c:\temp\DirectorySize.csv -type file -force | out-null;&lt;br&gt;
Add-Content c:\temp\DirectorySize.csv&amp;nbsp; $output; 
&lt;br&gt;
import-csv c:\temp\DirectorySize.csv;&lt;/pre&gt;
&lt;p&gt;
Since some might wonder what the heck I'm doing here (like myself, six months from
now) I thought I'd go through it line by line.
&lt;/p&gt;
&lt;p&gt;
Instansiate an empty&amp;nbsp;hash table
&lt;/p&gt;
&lt;pre&gt;$hashTbl=@{};&lt;/pre&gt;
&lt;p&gt;
Get a list of all children in the current directory and use where-object to get only
the objects that have the directory attibute i.e. just directories and not files.
&lt;/p&gt;
&lt;pre&gt;Get-ChildItem | where-object {$_.Mode -eq "d----"} | `&lt;/pre&gt;
&lt;p&gt;
The result from here is piped into a foreach-object that will do an operation for
each object.
&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;foreach-object&amp;nbsp; { `&lt;/pre&gt;
&lt;p&gt;
In this operation I display the Name of the folder. This will be outputted while the
script is running, giving me feedback on progress. The ; seperates commands.
&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp; $_.Name;`&lt;/pre&gt;
&lt;p&gt;
The next command might need a bit more explaining.
&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;$hashTbl[$_] = ( get-childitem($_.Name + "\documents")`&lt;br&gt;
-recurse -force| `&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;measure-object length -sum )&lt;/pre&gt;
&lt;p&gt;
From the inside and out: First we use get-childitem for the documents folder. $_ is
an auto-variable from the foreach and contains the current object in the loop. $_.Name
is the name of that folder. Add "\documents" to that to look at the sub-folder I want.
-recurse gets the children of all sub folders and -force includes hidden files.
&lt;/p&gt;
&lt;pre&gt;get-childitem($_.Name + "\documents") -recurse -force &lt;/pre&gt;
&lt;p&gt;
Then we pipe that into measure-object and tells it to sum the length property of all
the items returned from get-childitem.
&lt;/p&gt;
&lt;pre&gt;get-childitem($_.Name + "\documents") -recurse -force| `&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;measure-object length -sum )&lt;/pre&gt;
&lt;p&gt;
That creates a GenericMeasureInfo object that I put into the hashtable for later. 
&lt;/p&gt;
&lt;pre&gt;$hashTbl[$_] = ( get-childitem($_.Name + "\documents")`&lt;br&gt;
-recurse -force| `&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;measure-object length -sum )&lt;/pre&gt;
&lt;p&gt;
This loops though all the keys in the hashtable and outputs a string with the values
comma-separated. The {"Name,Size,File count"} is the &lt;em&gt;before&lt;/em&gt; statement in
the foreach that executes before the loop, outputting the headers for my comma-separated
list. The ( ) around everything makes it a list that I can save in $output.
&lt;/p&gt;
&lt;pre&gt;$output = ($hashTbl.psbase.keys |`&lt;br&gt;
&amp;nbsp;foreach `&lt;br&gt;
&amp;nbsp;&amp;nbsp;{"Name,Size,File count"} `&lt;br&gt;
&amp;nbsp;&amp;nbsp;{ $_.Name + "," + $hashTbl[$_].Sum + ","`&lt;br&gt;
+ $hashTbl[$_].Count } `&lt;br&gt;
&amp;nbsp;);&lt;/pre&gt;
&lt;p&gt;
Create a new file, overwriting any old file. Output is supressed.
&lt;/p&gt;
&lt;pre&gt;New-Item c:\temp\DirectorySize.csv -type file -force | out-null;&lt;/pre&gt;
&lt;p&gt;
Add the comma-separated list to the file.
&lt;/p&gt;
&lt;pre&gt;Add-Content c:\temp\DirectorySize.csv&amp;nbsp; $output; &lt;/pre&gt;
&lt;p&gt;
Read it and display it for information purposes only.
&lt;/p&gt;
&lt;pre&gt;import-csv c:\temp\DirectorySize.csv;&lt;/pre&gt;
&lt;p&gt;
There, all done. Any questions?
&lt;/p&gt;
&lt;a href="http://www.henriksen.no/content/binary/subSubDirSize.ps1"&gt;subSubDirSize.ps1
(,51 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://www.henriksen.no/aggbug.ashx?id=db4a6888-e713-46d9-9011-daaee138ece5" /&gt;</description>
      <comments>http://www.henriksen.no/CommentView,guid,db4a6888-e713-46d9-9011-daaee138ece5.aspx</comments>
      <category>Administration</category>
      <category>Powershell</category>
      <category>Scripting</category>
    </item>
  </channel>
</rss>