• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 47
  • Last Modified:

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
1
SAM IT
Asked:
SAM IT
  • 6
  • 5
1 Solution
 
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
 
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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now