Tuesday, March 25, 2014

Remove-ADComputer - The directory service can perform the requested operation only on a leaf object

I was performing server account clean up in AD an received the following error when running the Remove-ADComputer PowerShell cmdlet.

The directory service can perform the requested operation only on a leaf object


 It turns out, this server was not a leaf object.  Since it had child objects the Remove-ADObject cmdlet must be used to remove it from the domain. 

Running the following command removed the server from the domain:
get-adcomputer -identity servername | remove-adobject -recursive



4 comments:

  1. what if you have 500 computers to delete from AD?

    ReplyDelete
    Replies
    1. If you have the computers in a csv file you can use the: Import-Csv E:\mycomputer.csv | ForEach-Object

      I have a few examples of it being used here:
      http://kenumemoto.blogspot.com/p/adding-dns-alias-ps-c-add.html

      Delete
  2. I was facing the same issue , it was because the computer variable was containing spaces , i then clip the output and paste in excel and applied the trim formula , then i could delete the object without issue)

    ReplyDelete
  3. PS C:\Windows\system32> Import-Csv C:\comp.csv | foreach {Get-ADComputer -Identity $_.name |
    Remove-ADObject -Recursive}

    ReplyDelete