How do you move a user to another unit using Python

I had a game with the fantastic active_directory module by Tim Golden and the extensive python-ldap module, and while I see a great many articles on how to query, modify, create and delete entries in Active Directory using python. I can’t find any recommendations for moving a user to another unit using python for life. Is my google-foo failing or is it impossible? (I had great success with C #, but I prefer to work in python, where I can)

Thank you in advance

EDIT: Well, I did something else, and realized that I needed to use the MODRDN command. This is provided through Python_Ldap, so yay! ... However, I cannot convince python-ldap to authenticate using Windows credentials, so I played with pywin32. pywin32 is great for editing attributes, but I have not yet found a way to edit the distinguished name through this module ... ho-hum! Any clues would be really appreciated.

+4
source share
1 answer

Well, I solved it, and that is pretty good too. This solution is only for windows, I'm afraid, because it uses the pywin32 module (although under python-ldap you have modrdn, so you can solve it there too)

Ok Here's how to move user "jimboface" to OU "happyland"

import active_directory user = active_directory.find_user("jimboface") destination_ou = active_directory.find_ou("happyland") destination_ou.com_object.MoveHere(str(user.as_string()), str(user.Name)) #Thats it! 

Moments like this remind me why I love this language. Hope this helps someone!

+4
source

Source: https://habr.com/ru/post/1335382/


All Articles