Delete a protected OU using PowerShell

Delete an OU that is protected from accidental deletion using PowerShell

John Savill

February 24, 2016

1 Min Read
Delete a protected OU using PowerShell

Q. How can I delete a protected Organizational Unit with PowerShell?

A. Organizational Units are protected from accidental deletion which means if you try to delete an OU it will fail using PowerShell. The solution is to first remove the protection from accidental deletion. This can be done as follows:

Get-ADOrganizationalUnit -Identity 'OU=Avengers,DC=savilltech,DC=net' |    Set-ADObject -ProtectedFromAccidentalDeletion:$false -PassThru |    Remove-ADOrganizationalUnit -Confirm:$false

In the code example note that first the OU is selected and that object passed to the Set-ADObject which removes the accidental deletion protection with -passthru which sends the object of the OU to the next command which performs the delete. Neat!

Each week, John Savill answers all of your toughest tech questions about the worlds of Windows Server, Azure, and beyond. Read his past IT advice here, and email your questions to [email protected].

 

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like