0

I am prepping a script for our accounts management team that'll create users accounts fairly quickly. I seem to always get an error stating:

New-ADUser : A value for the attribute was not in the acceptable range of values

I have looked online and through here a bit but some of the solutions that others posted didn't work for me. The code is below:

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
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328

2 Answers2

0

You're passing '-StreetAddress "$Address"' but it's never supplied in the read-host section.

Lord Helmet
  • 150
  • 14
  • Thanks for the response! I made the change but i am still getting the same error. –  May 25 '16 at 13:24
0

Going out on a limb I'd guess that the error is caused by the value you provide for the property -Country. From the documentation:

Country

Specifies the country or region code for the user's language of choice. This parameter sets the Country property of a user object. The LDAP Display Name (ldapDisplayName) of this property is "c". This value is not used by Windows 2000.

The following example shows how set this parameter.
-Country "IN"

Change $Country = "United States" to $Country = "US" and the error should disappear.

See also this answer to a related question.

Community
  • 1
  • 1
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328