Delete a protected OU using PowerShell

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].

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.