1

I'm going round in circles and hoping someone can point me in the right direction...

I have created a .csv file as follows

SamAccountName,Name,GivenName,Surname,DisplayName,Type,Path,Logon Name,UserPrincipleName,ScriptPath,Password
fredflinstone,Fred Flinstone,Fred,Flinstone,Fred Flinstone,User,"CN=users,DC=Test,DC=local",fredf@test.local,fredf@test.local,login.bat,Yabba

I go to powershell, run

import-module activedirectory
Import-CSV C:\Users1.csv | New-ADUser

It successfully adds the users but the issues I have are

  1. it doesn't actually put in the Account User login name but does put in the pre 2000 name.
  2. it doesn't put in the password
  3. Even if I put in the Enabled field with the value $true they are still disabled

Any help would be appreciated

7
  1. Logon Name is not one of the parameters that New-ADUser takes. See http://technet.microsoft.com/en-us/library/ee617253.aspx for a list of what you can use.
  2. Password won't work this way, as it has to be a SecureString for security reasons. If you want to load the password from the cSV you'll have to turn this into a fuller script that can convery the value form the CSV into a secureString.
  3. I wonder if enabled is being set with the string "$true" instead of the boolean value,a s a result of coming thru a CSV file?
| improve this answer | |
  • 1
    Also, it's UserPrincipalName, not UserPrincipleName. – pk. Mar 15 '11 at 21:15
2

The Above are correct, you need to have UserPrincipalName something like this if gabbing information from an CSV:

-UserPrincipalName ($_.SamAccountName + '@' + $_.DomainName)

SamAccountName and DomainName are both Columns in my CSV spreadsheet.

| improve this answer | |
  • This works nicely, but isn't required--you can still manually specify the UPN if you want to. – SturdyErde Jun 12 '15 at 13:50
  • Yes, of course just like everything to be automatic :) thanks for the comments guys, just getting started here! – Lachie White Jun 15 '15 at 5:26
0
  1. You need to populate "userPrincipalName" for the "User Login Name".

  2. Get-Help Set-ADAccountPassword -examples : the first one shows you how to set an AD password.

  3. As you haven't set a password, you can't enable the account regardless.

So your script will have three calls:

Create the user (New-ADUser)
Set the password (Set-ADAccountPassword)
Enable the user (Set-ADUser)
| improve this answer | |
  • Thanks guys. I did have the spelling for Principal incorrect in the CSV file...that was my first issue. Since then we have completed this particular job. I just did a generic password manually and let them all set them. – Fred Mar 30 '11 at 8:38
0

Here is a variable option:

$a = Get-Date
$Man = $a.Month
$ti = $a.Hour
$min =$a.Minute
-AccountPassword (ConvertTo-SecureString -AsPlainText "Password$Man$ti$min" -Force)
| improve this answer | |
  • 2
    what is adding random numbers to the password supposed to accomplish? – Gerald Schneider Jan 24 '18 at 8:16
-1

The password part can be solved by this

-AccountPassword (ConvertTo-SecureString -AsPlainText "12345678" -Force)

where you can swap 12345678 with a variable.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.