新ADUser -Name长度太长

我需要为AD中的OU添加大约500个用户

我已经编写了我需要的所有东西,但是,它给出了错误: the name provided is not a properly formed

这是脚本

 New-ADUser -Name C080CAB1-9756-409F-914D-AE3971F67DE7 -Path "OU=Staging,DC=domain,DC=local" -accountPassword (convertto-securestring "zagreb+scotch8355" -asplaintext -force) -PasswordNeverExpires $True -CannotChangePassword $false -Enabled $true 

我跑了几个testing来解决问题是什么:

 New-ADUser -Name "C080CAB1-9756-409F-914D-AE3971F67DE7" -Path "OU=Staging,DC=domain,DC=local" -accountPassword (convertto-securestring "zagreb+scotch8355" -asplaintext -force) -PasswordNeverExpires $True -CannotChangePassword $false -Enabled $true New-ADUser -Name 'C080CAB1-9756-409F-914D-AE3971F67DE7' -Path "OU=Staging,DC=domain,DC=local" -accountPassword (convertto-securestring "zagreb+scotch8355" -asplaintext -force) -PasswordNeverExpires $True -CannotChangePassword $false -Enabled $true New-ADUser -Name C080CAB1`-9756`-409F`-914D`-AE3971F67DE7 -Path "OU=Staging,DC=domain,DC=local" -accountPassword (convertto-securestring "zagreb+scotch8355" -asplaintext -force) -PasswordNeverExpires $True -CannotChangePassword $false -Enabled $true 

随着其他一些变化

什么工作:

 New-ADUser -Name C080CAB1-9756-409F -Path "OU=Staging,DC=domain,DC=local" -accountPassword (convertto-securestring "zagreb+scotch8355" -asplaintext -force) -PasswordNeverExpires $True -CannotChangePassword $false -Enabled $true 

所以我认为这可能是一个长度问题,但我不知道如何让脚本工作。

    你想要显示名称到该string的string或login是36个string

    如果您使用的是服务器2012 R2,则只能将显示名称设置为20个字符,但login名最多可以使用64个字符(我认为)使用“-UserPrincipalName”

    尝试这个

     New-ADUser -Name C080CAB1-9756-409F-9 -UserPrincipalName C080CAB1-9756-409F-914D-AE3971F67DE7 -Path "OU=Staging,DC=domain,DC=local" -accountPassword (convertto-securestring "zagreb+scotch8355" -asplaintext -force) -PasswordNeverExpires $True -CannotChangePassword $false -Enabled $true 

    这将创build显示名称并截断-UserPrincipalName的值,该值将成为用户的用户login名。

    查看任何用户的属性来设置适当的标志。

    http://thenerdservice.com/useradd.png

    您可以看到200前login被截断,但用户login名不是

    http://thenerdservice.com/userlogin.png

    20个字符限制为sAMAccountName。 没有真正的方式。 有趣的是有256个字符(约120个Unicode)为它保留,但目录服务引擎只允许使用20个字符。

    编辑:让我更清楚一点。 您可以拥有超过20个字符的名称,但不能包含sAMAccountName。 这可能适合您的需求。 让我来certificate一下:

     New-ADUser C080CAB1-9756 # 20 character limit here Rename-ADObject 'CN=C080CAB1-9756,CN=Users,DC=lab,DC=com Get-ADUser C080CAB1-9756 DistinguishedName: CN=C080CAB1-9756-409F-914D-AE3971F67DE7,CN=Users,DC=lab,DC=com Name : C080CAB1-9756-409F-914D-AE3971F67DE7 SamAccountName : C080CAB1-9756 DisplayName :