Bulk Subnet Deletion

Dear All,

I have 1 VB script to delete 1 subnet 

strSubnetCN = "cn=192.168.1.0/26"     Set objRootDSE = GetObject("LDAP://RootDSE")  strConfigurationNC = objRootDSE.Get("configurationNamingContext")  strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & strConfigurationNC     Set objSubnetsContainer = GetObject(strSubnetsContainer)  objSubnetsContainer.Delete "subnet", strSubnetCN 

What if i hvae 1000 subnet need to be delete.

Kinldy help me into this...

July 24th, 2015 1:17pm

How about using PowerShell.

2012 R2 or 8.1

Remove-ADReplicationSubnet -Identity "10.0.0.0/25"  then read in the subnets from a text file with 'Get-Content'

If you want to use vb, read in the file:

Taken from here:http://www.developerscloset.com/?p=125

Option Explicit Dim objFile, strLine Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile= objFSO.OpenTextFile("C:\textfile.txt", 1) Do While Not objFile.AtEndOfStream strLine = objFile.readline

'Do your work here

WScript.Echo strLine Loop objFile.Close


Free Windows Admin Tool Kit Click here and download it now
July 24th, 2015 3:17pm

Please take back of AD then proceed with deletion if the subnet to be listed are couple then I will recommend manually deleting the same also if you have test lab then you can test any script in lab environment for the results and then proceed with production.

Create CSV file with below
              
Subnet,Mask
10.1.1.0,/24
192.168.1.0,/24
then do this

$Subnets = import-csv c:\subnets.csv
Foreach ($Subnet in $Subnets){
Get-QADObject -SearchRoot "CN=Subnets,CN=Sites,CN=Configuration,DC=DEVLAB,DC=LOCAL"  -searchscope onelevel |
Where {$_.Name -eq "$($Subnet.Subnet)$($Subnet.Mask)"} | remove qadobject
}

Powershell / quest commandlets script that can remove certain subnets for AD sites and services
Reference:http://www.experts-exchange.com/Software/Server_Software/Active_Directory/Q_27424178.html

This is not a scripting forum - if you are looking for assistance with scripting, you might want to refer to the PowerShell forum:
http://social.technet.microsoft.com/Forums/en/winserverpowershell/threads
http://social.technet.microsoft.com/Forums/en-US/category/scripting

Hope this helps

July 26th, 2015 7:15pm

Hi Lucky-MS,

Thanks for your post.

You could have a try to use Dsrm command.

https://technet.microsoft.com/en-us/library/cc731865.aspx?f=255&MSPPError=-2147217396

How to delete bulk subnets in AD Sites & Services ?

> for /f %i in (filename.txt) do dsrm %i  >>output.txt
Enter the subnets in a text file Eg : "filename.txt" which you want to delete.

http://social.technet.microsoft.com/wiki/contents/articles/2326.dsrm-commands.aspx

And for more support about the scripts, you could also post in powershell forum.

Best Regards

Mary Dong

Free Windows Admin Tool Kit Click here and download it now
July 27th, 2015 2:26am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics