Bart's Weblog

Just a blog…

PowerShell: Protect all OU’s in Active Directory from accidental deletion

Posted by bartvdw on 1313/0808/2011

1) Check which OUs aren’t protected:
Get-ADOrganizationalUnit -filter * -Properties ProtectedFromAccidentalDeletion | where {$_.ProtectedFromAccidentalDeletion -eq $false} | ft

2) Protect them:
Get-ADOrganizationalUnit -filter * -Properties ProtectedFromAccidentalDeletion | where {$_.ProtectedFromAccidentalDeletion -eq $false} | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true

3) Then rerun the first command to verify they have been changed.

These commands should run with "Active Directory Module for Windows PowerShell" for AD only or "PowerShell Modules" to load all of them.

AD DS: All OUs in this domain should be protected from accidental deletion
http://technet.microsoft.com/en-us/library/dd723677%28WS.10%29.aspx

Advertisements

9 Responses to “PowerShell: Protect all OU’s in Active Directory from accidental deletion”

  1. […] PowerShell: Protect all OU’s in Active Directory from accidental deletion LD_AddCustomAttr("AdOpt", "1"); LD_AddCustomAttr("Origin", "other"); LD_AddCustomAttr("theme_bg", "ffffff"); LD_AddCustomAttr("theme_border", "eeeeee"); LD_AddCustomAttr("theme_text", "555555"); LD_AddCustomAttr("theme_link", "2970A6"); LD_AddCustomAttr("theme_url", "c8c7c7"); LD_AddCustomAttr("LangId", "1"); LD_AddCustomAttr("Tag", "developement"); LD_AddCustomAttr("Tag", "ms-ad-group-policies-pki"); LD_AddCustomAttr("Tag", "powershell"); LD_AddSlot("LD_ROS_300-WEB"); LD_GetBids(); Share this:PrintEmailLike this:LikeBe the first to like this post. Categories: Developement, MS: AD, Group Policies, PKI Tags: Powershell Comments (0) Trackbacks (0) Leave a comment Trackback […]

  2. John Smith said

    you know these do not work

  3. John Smith said

    Anyone have some that do?

  4. Zsolt said

    Perfect script, thank you!

  5. Jack Marsh said

    It works if you first issue the import-module ActiveDirectory

    • bartvdw said

      Or use the “Active Directory Module for Windows PowerShell” shortcut from the administrative tools menu; both are exactly the same 🙂

  6. Bogdan Nemtanu said

    Perfect script, thank you!

  7. René said

    Thank you Bart!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: