I'm receiving the following error when the computer object has child objects.
Unable to delete object:
The directory service can perform the requested operation only on a leaf object.
Shared Function DeleteMachine(ByVal adPath As String, ByVal domain As String) As Boolean
Dim ctx As New PrincipalContext(ContextType.Domain, domain, "Domain\Username", "PWD")
Dim computer As ComputerPrincipal = ComputerPrincipal.FindByIdentity(ctx, adPath)
If computer IsNot Nothing Then
Catch ex As Exception
The user has right's do delete an object, if i manually delete the childs i can remove the computer object.
Can someone put some light on this?
I forgot to mention that the user don't have the AD DeleteTree permission.
The query "CN=MEANMACHINE,OU=Computers,DC=Contoso,DC=com" returns one object, in case the container is empty it deletes the computer, if the container has leafs, it throws the above error.
The path of the container leafs is, for instance, "CN=Virtual Machine,CN=MEANMACHINE,OU=Computers,DC=Contoso,DC=com"
Must i clean all leafs of a container first? How can i know if the container has leafs and how to iterate through them?