Powershell – Missing something when adding AD users with powershell

active-directorycsvpowershell

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

Best Answer

  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?