2

I'm having an issue with the following Powershell script. It is

a value for the attribute was not in the acceptable range of values Line 1 char 59

Import-Csv .\tableofusers.csv | foreach-object {New-ADUser -Path "ou=ou,dc=dc" -SamAccountName $_.SamAccountName -Name $_.name -DisplayName $_.name -GivenName $_.gn -SurName $_.sn -StreetAddress $_.SA -city $_.city -state $_.state -PostalCode $_.PostalCode -Country $_.Country -officephone $_.officephone -emailaddress $_.emailaddress -AccountPassword (ConvertTo-SecureString "Password1" -AsPlainText -force) -enabled $true -PasswordNeverExpires $false -Passthru}

I have been over it many times I cannot see the issue in or arround on character 59 any help would be welcome

4 Answers 4

1

it was country that was the problem, it took a bit but I was able to comment out most of the block until I found that $_.Country did not work

Sign up to request clarification or add additional context in comments.

Comments

0

Your piped variable token is wrong, it should be $_ rather than $ ie:

Import-Csv .\tableofusers.csv | foreach-object {New-ADUser -Path "ou=ou,dc=dc" -SamAccountName $_.SamAccountName -Name $_.name -DisplayName $_.name -GivenName $_.gn -SurName $_.sn -StreetAddress $_.SA -city $_.city -state $_.state -PostalCode $_.PostalCode -Country $_.Country -officephone $_.officephone -emailaddress $_.emailaddress -AccountPassword (ConvertTo-SecureString "Password1" -AsPlainText -force) -enabled $true -PasswordNeverExpires $false -Passthru}

This should do the trick.

4 Comments

Thanks, I looked at my script and I did have the $_. for each variable, for some reason when I pasted the script it did not include it,
Are any users from your spreadsheet imported ok? Replace {New-ADUser with {write-host $_.SamAccountName; New-ADUser This will write the SamAccountName of each user you import and help you spot which line is causing a problem.
Thanks, no users are being created I tried your suggestion and the lines look correct, the error line number is directly after the new-aduser
Ah ha, it was country that was the problem, it took a bit but I was able to comment out most of the block until I found that Country did not work
0

At a guess the value given to -country in the CSV file was something like United Kingdom instead of the code for the country which is GB.

You can look up a country code by setting the country/region in AD on the address page using the drop down list. Then whilst you have Advanced Features turned on (View>Advanced Features) open the user and on the Attribute Editor tab look look for the value of attribute c to see the code for the country you've set. Put that country code into the CSV file and it should work.

Comments

0

In my case it was using initials with more than 6 characters. Using dots between the initials means that > 6 is already reached when the initials are "A.B.C."

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.