Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

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

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
amendala
Asked:
amendala
  • 3
2 Solutions
 
yo_beeDirector of ITCommented:
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
 
KenMcFCommented:
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
 
KenMcFCommented:
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
 
amendalaAuthor Commented:
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
 
KenMcFCommented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now