Solved

Need a VB or Powershell script to mark all AD subnets as "Protected Against Accidental Deletion"

Posted on 2011-09-25
5
623 Views
Last Modified: 2012-05-12
Folks -

I'm looking for either a VB or Powershell script that will iterate through all the subnets defined in Active Directory Sites & Services and set their "Protect object against accidental deletion" permission.

Thanks for your help.
0
Comment
Question by:amendala
  • 3
5 Comments
 
LVL 22

Expert Comment

by:yo_bee
ID: 36596413
just out of curiosity how many subnets are we talking about?
I am currently looking up a PS script for you, but it might be easier to just manually set them if we are talking about a hand full.

0
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 36596483
What OS are you running? If you have 2008R2 or WIndows7 with the RSAT tools you can use the MS AD cmdlets and powershell. Here is an example. Even if you do not have 2008R2 DCs you can install the ADWS and run the cmdlets from a windows 7 workstation.
Foreach ($Subnet in (Get-ADObject -searchbase "cn=subnets,cn=sites,cn=configuration,DC=DEVLAB,DC=Local"  -searchscope 'onelevel' -filter *)){
Set-ADObject $Subnet -ProtectedFromAccidentalDeletion:$TRUE}

Open in new window

0
 
LVL 27

Expert Comment

by:KenMcF
ID: 36596512
And if you do not have 2008R2 or Win7 you can use the Quest AD cmdlets and powershell.


http://www.quest.com/powershell/activeroles-server.aspx

Foreach ($Subnet in (Get-QADObject -searchroot "cn=subnets,cn=sites,cn=configuration,DC=DEVLAB,DC=Local"  -searchscope 'onelevel')){
Add-QADPermission $subnet -Deny -Account Everyone -ApplyTo ThisObjectOnly -Rights DeleteTree,Delete}

Open in new window

0
 

Author Comment

by:amendala
ID: 36600593
KenMcF -

Thank you for your replies.  Your first reply works perfectly and is what I'm after.  Thank you for providing it to me.  I've tested it and all is well.

Can I get you to provide an additional script that will search subnets and report those that are NOT protected?  A simple report of their distinguished name would be sufficient.

I really appreciate your help.  If you don't have time for the other one, let me know and I'll close the question.
0
 
LVL 27

Assisted Solution

by:KenMcF
KenMcF earned 500 total points
ID: 36600755
No problem. This should give you what you need.


Get-ADObject -searchbase "cn=subnets,cn=sites,cn=configuration,DC=DEVLAB,DC=Local"  -searchscope 'onelevel' -filter * -properties * | Where {$_.ProtectedFromAccidentalDeletion -eq $False} | Select CN

Open in new window

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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…

791 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