我正在为我们的帐户管理团队准备一个脚本,该脚本可以非常快速地创建用户帐户。我似乎总是得到一个错误说明:
New-ADUser:属性的值不在可接受的值范围内
我已经在线查看了一下,但其他人发布的一些解决方案并不适用于我。代码如下:
Write-Host "New Business Services Account" -ForegroundColor Green
$Name = Read-Host "Enter First and Last Name"
$DisplayName = $Name
$GivenName = Read-Host "Enter First Name"
$Surname = Read-Host "Enter Last Name"
$EmailAddress = Read-Host "Enter Email Address"
$SamAccountName = Read-Host "Enter SamAccountName"
#$UserPrincipalName = $GivenName.$Surname + "@{entrustenergy}.com"
$Office = Read-Host "Enter Office"
$City = "Houston"
$State = "TX"
$ZipCode = Read-Host "Enter Zip Code"
$Country = "United States"
$Company = "Entrust Energy, Inc."
$JobTitle = Read-Host "Enter Job Title"
$Department = Read-Host "Enter Department"
$Manager = Read-Host "Enter Managers Username"
$Path = "PathOUisHere"
$Password = Read-Host "Enter Password"
New-ADUser -Name "$Name" -GivenName "$GivenName" -Surname "$Surname" `
-DisplayName "$DisplayName" -EmailAddress "$EmailAddress" `
-SamAccountName "$SamAccountName" -StreetAddress "$Address" -City "$City" `
-State "$State" -PostalCode "$ZipCode" -Country "$Country" `
-Company "$Company" -Title "$JobTitle" -Department "$Department `
-Manager "$Manager" -Path "$Path" -Enabled $true `
-AccountPassword (ConvertTo-SecureString "$Password" -AsPlainText -Force) `
-ChangePasswordAtLogon $true -PassThru
答案 0 :(得分:0)
您正在传递' -StreetAddress" $地址"'但它从未在读取主机部分提供。
答案 1 :(得分:0)
走出困境我猜测错误是由您为属性-Country
提供的值引起的。来自documentation:
国家
指定用户所选语言的国家或地区代码。此参数设置用户对象的Country属性。此属性的LDAP显示名称(ldapDisplayName)为" c"。 Windows 2000不使用此值。
以下示例显示如何设置此参数 -Country" IN"
将$Country = "United States"
更改为$Country = "US"
,错误就会消失。
另请参阅this answer相关问题。