Create New adusers in bulk using powershell

Create new bulk ADusers in my AD environment , below is the CSV format which i am using.I am looking for a script to create bulk user using below details in CSV, thanks in advance
(Conditions) -user cannot change the password and password never expires
CSV:-
SamAccountName,Firstname,DisplayName,Description,password
LVL 3
SAM ITAD windows Admin Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
I guess you have a column "LastName" as well?
And you might either want to add a column "Name" (the Common Name in AD, that is, the name the user will have in the ADUC's Name column) - currently it's just taken from SamAccountName.
Import-Csv -Path C:\Temp\NewADUser.csv | ForEach-Object {
	"Processing $($_.SamAccountName)" | Write-Host
	$splat = @{
		Name = $_.SamAccountName
		SamAccountName = $_.SamAccountName
		GivenName = $_.FirstName
		Surname = $_.LastName
		DisplayName = $_.DisplayName
		Description = $_.Description
		PasswordNeverExpires = $true
		CannotChangePassword = $true
		AccountPassword = ConvertTo-SecureString $_.Password -asPlaintext -Force
	}
	New-ADUser @splat
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SAM ITAD windows Admin  Author Commented:
Can't we import password from CSV ? for each user
0
oBdACommented:
Yes? That's what line 12 does.
New users are disabled by default - is it that what you mean? And on closer inspection, you might want to add a column UserPrincipalName and change line 6 accordingly; this version will now use the SamAccountName plus the AD domain name.
Import-Csv -Path C:\Temp\NewADUser.csv | ForEach-Object {
	"Processing $($_.SamAccountName)" | Write-Host
	$splat = @{
		Name = $_.SamAccountName
		SamAccountName = $_.SamAccountName
		UserPrincipalName = "$($_.SamAccountName)@${ENV:UserDnsDomain}"
		GivenName = $_.FirstName
		Surname = $_.LastName
		DisplayName = $_.DisplayName
		Description = $_.Description
		PasswordNeverExpires = $true
		CannotChangePassword = $true
		Enabled = $true
		AccountPassword = ConvertTo-SecureString $_.Password -asPlaintext -Force
	}
	New-ADUser @splat
}

Open in new window

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.

SAM ITAD windows Admin  Author Commented:
In line 12 i can see CannotChangePassword = $true

Where I need to specify the password for each user going to be created?
0
oBdACommented:
Line 12 in the first script, line 14 in the new one, and it will evaluate the column "password", just like described in your question.
0
SAM ITAD windows Admin  Author Commented:
password will be unique for each user, using csv column can we import the passwords for each user
0
oBdACommented:
Again: the script will evaluate the column "password", just like described in your question.
Strictly informational: The argument for New-ADUser is "AccountPassword", and it will be set in line 14 in the second script.
0
SAM ITAD windows Admin  Author Commented:
Then the input CSV file should be in below format . Correct me if am wrong

Name, SamAccountName ,GivenName ,DisplayName ,Description ,AccountPassword
0
oBdACommented:
No. You defined your csv in your question as
SamAccountName, Firstname, DisplayName, Description, password
, so that's what the script is using.
But as mentioned in https:#a42548961, you should have a column "LastName" (since you have "FirstName"); if you really don't, remove line 8 from the latest script version, "Surname = $_.LastName".
0
SAM ITAD windows Admin  Author Commented:
Perfect ...thanks a lot
0
SAM ITAD windows Admin  Author Commented:
Perfect
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.