Jump to content

Create Bulk AD Users from CSV using Powershell Script


Recommended Posts

Posted

Dear all,

 

I am using below script to Create Bulk AD Users from CSV. Filewhich contains set of New AD Users to create with the attributes Name, samAccountName and ParentOU. I want add the first name, last name, display name and groups to the csv file. Can anyone guide me what to change ?

 

Import-Module ActiveDirectory

Import-Csv "C:\Scripts\NewUsers.csv" | ForEach-Object {

$userPrincinpal = $_."samAccountName" + "@TestDomain.Local"

New-ADUser -Name $_.Name `

-Path $_."ParentOU" `

-SamAccountName $_."samAccountName" `

-UserPrincipalName $userPrincinpal `

-AccountPassword (ConvertTo-SecureString "MyPassword123" -AsPlainText -Force) `

-ChangePasswordAtLogon $true `

-Enabled $true

Add-ADGroupMember "Domain Admins" $_."samAccountName";

}

 

Thanks

Posted

Import-Csv CSV LOCATION PATH | Foreach-object {
New-ADUser -Name $_.DisplayName -UserPrincipalName $_.UserPrincipalName -SamAccountName $_.Username -GivenName $_.GivenName -DisplayName $_.DisplayName -Surname $_.Surname -Description $_.Description -Path $_.Path -ScriptPath $_.ScriptPath -HomeDirectory $_.Homedirectory -HomeDrive $_.HomeDrive -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -Force) -Enabled $True -PasswordNeverExpires $False -ChangePasswordAtLogon $True  -PassThru }

 

example of what i use to import users with currently

Posted

here are the headers that i use on my CSV file

 

Username,GivenName,Surname,DisplayName,UserPrincipalName,Password,Description,Homedirectory,HomeDrive,ScriptPath,Path

 

this gives me a user with populated fields for

username

Given Name (1st name)

surname

display name

the UPN

password

Description

Home Dir & Home Dir details and the OU path

  • Thanks 1
Posted

I am just doing the same at my school and this thread has been really helpful. My powershell script works fine, but the problem that I have is that the users home folder is not created, is there another command that needs to be run to create the home folder and set permissions?

 

Thanks

Posted

the script wont actually create the home folder it just adds the path into the users AD settings.

 

for creating users directories i have another batch script (using md net share & icalcs) its a little old hat but works as i havent got round to looking at a powershell based alternative.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...