Avatar of xzay1967
xzay1967
 asked on

Need powershell script to create multiple users

Hey everyone, I am on a project that is requiring me to create a 1000 AD accounts. I have a csv file that is already populated with the names. There are two columns, FirstName and LastName. Can someone please provide a powershell script that can create the users. I know how to edit the script to meet my domain, OU , password etc.
PowershellActive DirectoryExchange

Avatar of undefined
Last Comment
xzay1967

8/22/2022 - Mon
Rajkumar Duraisamy

Create a csv file with the these details

name, alias, UserPN, password
Username1, Aliasname1, username1@domainname.com, yourpassword

save the file in c drive or ur wish and then run this shell command

import-csv c:\newusers.csv | foreach {New-Mailbox -Name $_.name -Alias $_.alias  -UserPrincipalName $_.UserPN -Database “Your mailbox database name” -Org Users -ResetpasswordonNextlogon $true -Password (ConvertTo-SecureString $_.password -AsPlainText -Force)}
Mysidia

Import-Module  ActiveDirectory

$password = ConvertTo-SecureString "mypassword" -asplaintext -force

Import-CSV users.csv | foreach {  New-ADUser -Path "OU=SomeUserOU,DC=EXAMPLE,DC=COM" -AccountPassword $password  -ChangePasswordAtLogon  -GivenName $_.FirstName -Surname $_.LastName    -SAMAccountName  ("{0}{1}"  -f $_.FirstName, $_.LastName )  -UserPrincipalName  ("{0}{1}@EXAMPLE.COM"  -f $_.FirstName, $_.LastName )  -DisplayName  ("{0} {1}"  -f $_.FirstName, $_.LastName )     -Name  ("{0} {1}"  -f $_.FirstName, $_.LastName )  -AllowReversiblePasswordEncryption $false  -Enabled $true  }
yo_bee

You can also use csvde -i to import into AD.
This is another means.
http://technet.microsoft.com/en-us/library/cc732101(v=ws.10)
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
xzay1967

ASKER
Thanks for the scripts guys, @ Rajkumar-MCITP, I did not try your script because I do not want to create any mailboxes, if you edit it to not create mailboxes, then I will. @ Misidia, I tried yours but it generated errors as shown in the attached screenshot. I aklo attached your script to show what changes I made. I left my csv file with the same two original columns, FirstName and LastName.
powershell-error.png
Users.txt
Rajkumar Duraisamy

xzay1967

ASKER
Thanks  Rajkumar-MCITP but it really does not, but just so I get a better understanding:
Is the first section defining what columns are  expected to be in the csv file? With that being said, if those columns are not there, will the script just use the ones there? In my case, I only have two colums, FirstName, and LastName.
CSV...
Name,Password,Description,OU,TSPath
Test001,Metro123,Ellipse Regression Testing account,"OU=NewUsers,OU=Testing,OU=Users,OU=Company,DC=local",\\company.local\data\Profiles-L-Z\Test001

**********************************
Where in here do I define what the password is?

PS Script Quest Powershell script

import-csv C:\TEMP\Connex\EllipseTestusers.csv | foreach {New-QADUser -Name $_.Name -UserPassword $_.Password -SamAccountName $_.Name -FirstName $_.Name -DisplayName $_.Name -ParentContainer $_.OU -UserPrincipalName ($_.Name+$domain) -Description $_.Description; Set-QADUser -Identity $_.Name -PasswordNeverExpires $true -TsProfilePath $_.TSPath}


Based on the errors in the screenshot, what is the solution? I added $false to the changepasswordatlogon, yet I still get an error about it.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Rajkumar Duraisamy

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
xzay1967

ASKER
Again, thanks for your help. I assume this would mean that users will be required to change password at next logon, hence no parameter for -changepassowordatlogon. I will test and note results