Deleting a Subnet






Deleting a Subnet

Problem

You want to delete a subnet object.

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. Right-click on the subnet you wish to remove and select Delete.

  5. Click Yes to confirm.

Using a command-line interface

You can delete a subnet object using the built-in dsrm utility or AdMod. The dsrm utility takes the following syntax:

	> dsrm cn=<SubnetName>,cn=subnets,cn=sites,cn=configuration,<ForestRootDN>

To remove a subnet using AdMod, use this syntax:

	> admod b cn=<SubnetName>,cn=subnets,cn=sites,cn=configuration,<ForestRootDN> -del\

Using VBScript
	strSubnetName = "cn=<SubnetName>" ' e.g. "cn=10.0.0.0/8"
	strParentDN = cn=subnets,cn=sites,cn=configuration," _
	              & strForestDN
	strForestDN = "<ForestRootDN>" ' e.g. "dc=rallencorp,dc=com"

	set objContainer = GetObject("LDAP://" & strParentDN)
	objContainer.Delete "subnet", strSubnetName

Discussion

Using VBScript

This script example uses the IADsContainer::Delete method to delete the subnet object. To use this method, you must first bind to the parent container of the object. You then call Delete by passing the object class along with the RDN of the object that you want to delete.

The Delete method is a safer alternative to the DeleteObject method because you need to be more explicit about what you are deleting. With DeleteObject, you only have to specify the distinguished name of an object and it will summarily delete it. For example, the following code will delete a subnet object using DeleteObject:

	strSubnetDN = "<SubnetDN>"
	set objSubnet = GetObject("LDAP://" & strObjectDN)
	objSubnet.DeleteObject(0)

As you can see, if a user accidentally or maliciously mistypes an inappropriate DN, the result could be disastrous. Using the DeleteObject method puts more constraints on the delete operation.

See Also

Recipe 4.25 for deleting a container object, MS KB 258310 (Viewing Deleted Objects in Active Directory), MSDN: IADsContainer::Delete, and MSDN: IADsDeleteOps:: DeleteObject



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows