使用System Manager PowerShell创建AD用户遇格式错误求助
问题描述
我尝试通过AWS System Manager执行PowerShell命令,在EC2实例托管的Active Directory中创建AD用户,执行命令如下:
New-ADUser -Name 'Batman Gotham' -AccountPassword (ConvertTo-SecureString 'Password@1234' -AsPlainText -Force) -DisplayName 'Batman Gotham' -GivenName 'Batman' -SamAccountName 'batman.gotham@darknight.com' -Surname 'Gotham' -EmailAddress 'batman.gotham@darknight.com' -UserPrincipalName 'batman.gotham@darknight.com' -MobilePhone '8888888888' -Title 'Staff Super Hero' -Department 'Batman Cloud Services' -Enabled $True -StreetAddress 'Gotham Street' -City 'Gotham' -State 'CA' -Country 'USA' -Path 'CN=Users,OU=Operations,DC=darknight,DC=com' -employeeNumber '1234567' -ChangePasswordAtLogon $True
但在System Manager中收到如下错误,且无法获取更多错误详情:
New-ADUser : The name provided is not a properly formed account name At C:\ProgramData\Amazon\SSM\InstanceData\i-instanceid\document\orchestr\ation\853f5c41-fcbf-44e0-b7fb-qwe1234redfdd\awsrunPowerShellScript\0.awsrunPowerShellScript\_script.ps1:1 char:1 + New-ADUser -Name 'Batman Gotham' -AccountPassword (ConvertTo-SecureString 'Passw ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : NotSpecified: (CN=Batman Gotha...darknight,DC=com :String) [New-ADUser], ADException + FullyQualifiedErrorId : ActiveDirectoryServer:1315,Microsoft.ActiveDirectory.Management.Commands.NewADUser
问题原因及解决办法
这个错误的核心是账户名称格式不符合AD规则,问题出在-SamAccountName参数上:
- Active Directory的
SamAccountName(预Windows 2000登录名)不允许包含@符号,它的格式规则是最多20个字符,仅支持字母、数字,以及! # $ % ^ & * ( ) _ - . { } ~这类符号,不能包含@、空格等特殊字符。你当前设置的batman.gotham@darknight.com包含了@,违反了规则。
解决步骤:
- 将
-SamAccountName 'batman.gotham@darknight.com'修改为不带@的合法名称,比如-SamAccountName 'batman.gotham' - 确认
-Path指定的AD路径CN=Users,OU=Operations,DC=darknight,DC=com确实存在,避免路径不存在导致的衍生错误 - 确认密码符合你的AD域密码策略(如果有配置)
修改后的完整命令示例:
New-ADUser -Name 'Batman Gotham' -AccountPassword (ConvertTo-SecureString 'Password@1234' -AsPlainText -Force) -DisplayName 'Batman Gotham' -GivenName 'Batman' -SamAccountName 'batman.gotham' -Surname 'Gotham' -EmailAddress 'batman.gotham@darknight.com' -UserPrincipalName 'batman.gotham@darknight.com' -MobilePhone '8888888888' -Title 'Staff Super Hero' -Department 'Batman Cloud Services' -Enabled $True -StreetAddress 'Gotham Street' -City 'Gotham' -State 'CA' -Country 'USA' -Path 'CN=Users,OU=Operations,DC=darknight,DC=com' -employeeNumber '1234567' -ChangePasswordAtLogon $True
内容的提问来源于stack exchange,提问作者K P
相关产品推荐
相关产品推荐

