Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3481
  • Last Modified:

New-ADUser to add bulk users with csv file

Import-Csv "c:\importausers.csv" | foreach-object {
$userprinicpalname = $_.SamAccountName + "@mydomain.com"
New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $_.name -DisplayName $_.name -GivenName $_.GivenName -SurName $_.SurName -emailAddress $_.emailAddress -Description $_.Description -Path "OU=Users,DC=domain,,DC=com" -AccountPassword (ConvertTo-SecureString "Passw0rd" -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True}

CSV file headings are:
SamAccountName,name,GivenName,Surname,emailAddress,Description

I keep getting error:
New-ADUser :directory object not found
at c:\createaduser.ps1:3 char:11
0
jazmanuni
Asked:
jazmanuni
  • 3
  • 2
2 Solutions
 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
This command cannot be run from Exchange shell .... but Active Directory PowerShell

New-ADUser
http://technet.microsoft.com/en-us/library/ee617253.aspx

- Rancy
0
 
PeteJThomasCommented:
Is that an exact copy and paste of your script?

As you've made a typo in the 4th line down from the top - "$userprinicpalname" instead of "$userprincipalname"...
0
 
PeteJThomasCommented:
Oh don't worry, I can see the typo is also there where the variable is created so the fact that it's a typo won't make any difference! Ignore me! :)
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
PeteJThomasCommented:
You might want to take a look at this: http://www.windowsitpro.com/blog/powershell-with-a-purpose-blog-36/scripting-languages/import-users-into-ad-with-one-line-and-two-commands-137390

It's a simplified way of achieiving the same, based on the assumption that your csv column headers MUST be accurately spelt, and every attribute you want to specify (including path etc.) listed in the .csv.

But the idea is that you could achieve the same thing simply be typing:

Import-csv "c:\importausers.csv" | New-ADUser

Looks a lot simpler to me than the method you're currently using...

HTH

Pete
0
 
jazmanuniAuthor Commented:
Its being run from a DC Win 2008 R2, Powershell v2 (Not Exchange Powershell) with
>Import-Module Active Directory

Yes I see you dont have to define the variables in the script of they exist in the csv file.

Its working now, I will show it here if it helps anyone else..

CSV Headers for file c:\bulkaddadusers.csv

SAMAccountname,Name,DisplayName,userPrincipalName,GivenName,Surname,emailAddress,Description

Method:
1. Open powershell as administrator on DC
2. >Import-Module Active Directory
3. >Import-csv "c:\bulkaddadusers.csv | New-ADUser -AccountPassword (ConvertTo-SecureString -AsPlaintext "Pa$$w0rd" -Force | Enable-ADAccount

All the enabled users will be created in the default OU = Users

Cheers
0
 
jazmanuniAuthor Commented:
Exact method defined
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now