Link to home
Create AccountLog in
Avatar of 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.
Avatar of Rajkumar Duraisamy
Rajkumar Duraisamy
Flag of India image

Create a csv file with the these details

name, alias, UserPN, password
Username1, Aliasname1,, 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 $ -Alias $_.alias  -UserPrincipalName $_.UserPN -Database “Your mailbox database name” -Org Users -ResetpasswordonNextlogon $true -Password (ConvertTo-SecureString $_.password -AsPlainText -Force)}
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  }
You can also use csvde -i to import into AD.
This is another means.
Avatar of xzay1967


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.
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.
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.
Avatar of Rajkumar Duraisamy
Rajkumar Duraisamy
Flag of India image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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