Link to home
Start Free TrialLog in
Avatar of SAM IT
SAM IT

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SAM IT
SAM IT

ASKER

Can't we import password from CSV ? for each user
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

Avatar of SAM IT

ASKER

In line 12 i can see CannotChangePassword = $true

Where I need to specify the password for each user going to be created?
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.
Avatar of SAM IT

ASKER

password will be unique for each user, using csv column can we import the passwords for each user
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.
Avatar of SAM IT

ASKER

Then the input CSV file should be in below format . Correct me if am wrong

Name, SamAccountName ,GivenName ,DisplayName ,Description ,AccountPassword
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".
Avatar of SAM IT

ASKER

Perfect ...thanks a lot
Avatar of SAM IT

ASKER

Perfect