Skip to Content
Active Directory Cookbook
book

Active Directory Cookbook

by Robbie Allen
September 2003
Intermediate to advanced
624 pages
15h 49m
English
O'Reilly Media, Inc.
Content preview from Active Directory Cookbook

11.5. Listing the Subnets

Problem

You want to list the subnet objects in Active Directory.

Solution

Using a graphical user interface

  1. Open the Active Directory Sites and Services snap-in.

  2. Click on the Subnets container.

  3. The list of subnets will be displayed in the right pane.

  4. To view the properties of a specific subnet, double-click on the one you want to view.

Using a command-line interface

The following command will list all subnets:

> dsquery subnet

The following command will display the properties for a particular subnet. Replace <Subnet> with the subnet address and mask (e.g., 10.5.3.0/24):

> dsget subnet "<Subnet>"

Using VBScript

' This code lists all the subnets stored in Active Directory.
set objRootDSE = GetObject("LDAP://RootDSE")
set objSubnetsCont = GetObject("LDAP://cn=subnets,cn=sites," & _
                               objRootDSE.Get("configurationNamingContext") )
objSubnetsCont.Filter = Array("subnet")
for each objSubnet in objSubnetsCont
   Wscript.Echo "  " & objSubnet.Get("cn")
next

Discussion

To display the site that subnets are associated with, include the siteObject attribute as one of the attributes to return from the query. For example, the second to last line of the VBScript solution could be modified to return the site by using this code:

Wscript.Echo "  " & objSubnet.Get("cn") & " : " & objSubnet.Get("siteObject")

See Also

MS KB 323349 (HOW TO: Configure Subnets in Windows Server 2003 Active Directory)

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Active Directory Administration Cookbook

Active Directory Administration Cookbook

Sander Berkouwer
Active Directory Cookbook, 3rd Edition

Active Directory Cookbook, 3rd Edition

Laura E. Hunter, Robbie Allen
Active Directory Cookbook, 4th Edition

Active Directory Cookbook, 4th Edition

Brian Svidergol, Robbie Allen

Publisher Resources

ISBN: 0596004648Supplemental ContentCatalog PageErrata