将用户添加到AD使用PowerShell用户、AD、PowerShell

由网友(清泪入喉)分享简介:我有一个关于如何使用PowerShell的用户添加到AD的问题,我已经写了一个小脚本,但我总是得到一个错误,当我尝试创建一个用户。I have a question about how to add users to AD using powershell, ive written a small script bu...

我有一个关于如何使用PowerShell的用户添加到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@e.com")
            $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?

在此先感谢。

推荐答案

试试这个:

$container = [ADSI] "LDAP://dc.sopragroup.lan/cn=Users,dc=sopragroup,dc=lan"
$UserName = "user"
$User = $container.Create("User", "cn=" + $UserName)
$User.Put("sAMAccountName", $UserName)
$User.Put("givenName", "Test")
$User.Put("sn", "Person")
$User.Put("mail", "email@e.com")
$User.SetInfo()
$User.psbase.InvokeSet('AccountDisabled', $false)
$User.SetInfo()
$User.SetPassword("P@55w0rd")
阅读全文

相关推荐

最新文章