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
what if you have 500 computers to delete from AD?
ReplyDeleteIf you have the computers in a csv file you can use the: Import-Csv E:\mycomputer.csv | ForEach-Object
DeleteI have a few examples of it being used here:
http://kenumemoto.blogspot.com/p/adding-dns-alias-ps-c-add.html
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)
ReplyDeletePS C:\Windows\system32> Import-Csv C:\comp.csv | foreach {Get-ADComputer -Identity $_.name |
ReplyDeleteRemove-ADObject -Recursive}