New-ADUser -Name 长度太长

Ant*_*ito 13 powershell active-directory windows-server-2012-r2

我需要向 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
Run Code Online (Sandbox Code Playgroud)

我进行了几个测试以确认问题是什么:

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
Run Code Online (Sandbox Code Playgroud)

连同其他几个变体

什么起作用了:

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
Run Code Online (Sandbox Code Playgroud)

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

Bri*_*ess 13

你想显示名称到那个 36 个字符的字符串还是登录名是 36 个字符的字符串

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

尝试这个

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
Run Code Online (Sandbox Code Playgroud)

这将创建显示名称并截断 -UserPrincipalName 的值,这将是用户的用户登录名。

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

http://thenerdservice.com/useradd.png

您可以看到 pre-200 登录被截断,但用户登录名不是

http://thenerdservice.com/userlogin.png


Rya*_*ies 11

sAMAccountName 不得超过 20 个字符。没有真正的解决办法。有趣的是,为它保留了 256 个字符(约 120 个 Unicode),但目录服务引擎只允许您使用 20 个。

编辑:让我更清楚一点。你可以有超过20个字符的名称,但不是sAMAccountName赋。这可能适合您的需求。让我演示一下:

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      :
Run Code Online (Sandbox Code Playgroud)