Solved

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

Posted on 2011-09-25
5
613 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 21

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now