如何将用户移动到不同的OU使用Python [英] How do you move a user to a different OU using Python

查看:542
本文介绍了如何将用户移动到不同的OU使用Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直有与梦幻般的 active_directory模块蒂姆黄金和广泛的python-LDAP模块,虽然我看到的关于如何查询,修改,创建和蟒蛇在活动目录中删除条目,文章一大摆我不能为我的生活中找到移动用户在不同的任何意见使用python OU。 是我的谷歌,富失败我还是这不可能? (我已经用C#巨大的成功,但我preFER在Python的工作,我可以)

I've been having a play with the fantastic active_directory module from Tim Golden and the extensive python-ldap module and while I see a great slew of articles on how to query, modify, create and delete entries within Active Directory from python I can't for the life of me find any advise on moving a user to a different OU using python. Is my google-foo failing me or is this not possible? (I've had great success with c# but I prefer to work in python where I can)

在此先感谢

编辑: 好了,我已经做了一些更多的挖掘和实现我需要使用的如果是modrdn命令。这是通过Python_Ldap提供这样耶!......不过,我似乎无法哄蟒蛇,LDAP为使用Windows凭据,所以我一直在玩pywin32认证。 pywin32是美妙的编辑属性,但是我还没有还没有找到一种方法,通过该模块......乏味的编辑专有名称!任何线索将是真正的AP preciated。

OK, I've done some more digging and realized I need to be using the MODRDN command. This is provided through Python_Ldap so yay!...However I can't seem to coax python-ldap into authenticating using Windows credentials so I have been playing with pywin32. pywin32 is wonderful for editing attributes but I havent yet found a way to edit the distinguished name through this module...ho-hum! Any clues would be really appreciated.

推荐答案

好吧,我已经解决了它,和它的相当不错了。 这是一个Windows唯一的解决办法我怕因为这样使用pywin32模块(虽然下的python-LDAP你如果是modrdn这样你就可以解决这个问题有太多)

Ok I've solved it, and its rather nice too. This is a windows only solution I'm afraid as this uses the pywin32 module (though under python-ldap you have modrdn so you can solve it there too)

确定这里是如何移动用户jimboface为OUhappyland

Ok Here is 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 my why I love this language. Hope this helps someone!

这篇关于如何将用户移动到不同的OU使用Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆