Subscribe to Windows IT Pro
September 11, 2006 12:00 AM

A Creative (and Easy) Way to Assign IP Subnets to AD Sites

This seemingly tedious task turned out to be a satisfying project
Windows IT Pro
InstantDoc ID #93172
Rating: (0)
Downloads
93172.zip

Using Subs2site.vbs
I used Subs2site.vbs, which Listing 2 shows to import the subnets into AD. Although I could’ve written this code using Visual Basic Editor, I instead chose to adapt an existing script to save time. You can download Subs2site.vbs by clicking the Download the Code Here button above.

Subs2site.vbs is somewhat limited in that it can import subnets to only one site at a time. Thus, if the extracted subnets need to be imported to different sites, you need to group the extracted subnets by site and save the groups in separate files.

To use Subs2site.vbs, follow these steps:

  1. Make sure that the C:\Subnets\subnets.txt file contains the subnets you want to import to a particular site.
  2. Open Subs2site.vbs in a text editor such as Notepad.
  3. In the code at callout A in Listing 2, change the strSiteObjectRDN variable’s value to the target AD site.
  4. If you have 16-bit subnets, change /24 to /16 in the code at callout B in Listing 2.
  5. Run Subs2site.vbs from the command-shell window by simply typing subs2site.vbs and pressing Enter. You must have sufficient permissions to access AD for this script to work.

Subs2site.vbs will then import the listed subnets to the specified AD site. Note that if a particular subnet already exists in that site, the On Error Resume Next statement allows the script to continue to the next subnet without causing the script to end with an error. If you have multiple sites to which you want to assign subnets, you simply repeat steps 1 through 5 for each site.

A Creative Solution
Thanks to Visual Basic Editor, I was able to be resourceful and even a little artistic in devising a solution to the subnet problem. Even better, the Subnets macro and Subs2site.vbs script let me reduce a substantial task into a handful of mouse clicks and keystrokes.

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.