diff --git a/python/samba/netcmd/user.py b/python/samba/netcmd/user.py index 5adc2879bcc..43581703bfd 100644 --- a/python/samba/netcmd/user.py +++ b/python/samba/netcmd/user.py @@ -406,10 +406,23 @@ Example2 shows how to delete a user in the domain against the local server. su lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True) + samdb = SamDB(url=H, session_info=system_session(), + credentials=creds, lp=lp) + + filter = ("(&(sAMAccountName=%s)(sAMAccountType=805306368))" % + username) + try: - samdb = SamDB(url=H, session_info=system_session(), - credentials=creds, lp=lp) - samdb.deleteuser(username) + res = samdb.search(base=samdb.domain_dn(), + scope=ldb.SCOPE_SUBTREE, + expression=filter, + attrs=["dn"]) + user_dn = res[0].dn + except IndexError: + raise CommandError('Unable to find user "%s"' % (username)) + + try: + samdb.delete(user_dn) except Exception, e: raise CommandError('Failed to remove user "%s"' % username, e) self.outf.write("Deleted user %s\n" % username)