使用 powershell 将用户添加到 AD
我有一个关于如何使用 powershell 将用户添加到 AD 的问题,我编写了一个小脚本,但当我尝试创建用户时总是收到错误。
$connection= "LDAP://ou=Users, dc="domain", dc="com"
$OU = [adsi] $Connection
$User = $OU.Create("user", "Test Person")
$User.Put("Firstname", "Test")
$User.Put("Surname", Person)
$User.Put("Email", "[email protected]")
$User.SetInfo()
我认为我的连接字符串是错误的,但我已经尝试了不同的方法,但仍然没有成功。这是我在本地尝试的。需要让它工作,但通常我的 AD 位于不同的服务器上,那么该怎么办?
提前致谢。
I have a question about how to add users to AD using powershell, ive written a small script but i always get an error when i try to create a user.
$connection= "LDAP://ou=Users, dc="domain", dc="com"
$OU = [adsi] $Connection
$User = $OU.Create("user", "Test Person")
$User.Put("Firstname", "Test")
$User.Put("Surname", Person)
$User.Put("Email", "[email protected]")
$User.SetInfo()
I think my connection string is wrong, but i tried different ways already and still no success. This im trying locally. Need to get it working but then normally my AD is on different server, how to do it then?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下:
Give this a try:
这是另一个示例(@Andy Arismendi 是第一个),其中包含其他一些详细信息:
DirectoryEntry< /code> 构造函数
attribute=value
。在 Active-Directory 中,您无法选择架构强加的属性。对于user
或inetOrgPerson
来说,它是CN
;对于organizationalUnit
来说,它是OU
。在您的例子中,对象的名称是CN=Test Person
。您将在此处找到 OU 和用户的创建。
Here is another example (@Andy Arismendi was first) with some other details:
DirectoryEntry
constructorattribute=value
. In Active-Directory you can't choose the the attribute it's imposed by the schema. For auser
or aninetOrgPerson
it'sCN
for anorganizationalUnit
it'sOU
. In your case the name of the object isCN=Test Person
.You'll find here under the creation of an OU and a user.