Powershell / quest commandlets script that can remove certain subnets for AD sites and services

Posted on 2011-10-31
Medium Priority
Last Modified: 2012-05-12
Powershell / quest commandlets script that can remove certain subnets for AD sites and services.  We are consolidating AD sites and services and do not want to manually have to do this.  We have many subnets.
Question by:mjm21
  • 2
  • 2
LVL 27

Expert Comment

ID: 37058601
Here is one example to remove a single subnet of If you have a text file you could read the text file on subnets and loop through to delete all.

Get-QADObject -SearchRoot "CN=Subnets,CN=Sites,CN=Configuration,DC=DEVLAB,DC=LOCAL"  -searchscope onelevel | Where {$_.Name -eq ""} | remove qadobject

Author Comment

ID: 37063970
thanks very much

If I have a csv how the script look like to pulll from the list and delete all?  I would appreciate it!
LVL 27

Accepted Solution

KenMcF earned 2000 total points
ID: 37064215
What format is the CSV file in?

If it is like this


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

Open in new window


Author Comment

ID: 37064977
awsome !  I will try.....thanks a lot

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question