Link to home
Start Free TrialLog in
Avatar of petaganayr
petaganayr

asked on

Import User Accounts into Active Direcotry

Hello Experts,

I am wondering if anyone could help me with creating a powershell script. I think I can put together a PS script from videos and articles from the Internet but I'd like to add a few specific things to it:

Use a csv file to import user accounts into Active Directory.
Before the import happens, the script checks whether the account has already been created, if so, it skips the user account and process the next account.
After the import completes, the script deletes the file.

Thank you!
Avatar of Joshua Grantom
Joshua Grantom
Flag of United States of America image

What attributes are included in the csv file?

Are they the basics?

First Name, Middle Initial, Last Name, email?

Do you want to set a temporary password?
SOLUTION
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

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 petaganayr
petaganayr

ASKER

Joshua,

Just the basics - Firstname, LastName, Name.

Is there a way to import users without a password?

Thank you.
SOLUTION
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
You have to be careful that if you do not specify an AccountPassword then the account will be disabled by default unless you specifically enable the account in the script.

Just remove what you do not need in my script and it will work without issue.

Will.
Thank you for the scripts I will try them soon, probably tonight.

I have a couple of stupid questions, I guess I could try these myself, but I am wondering if you guys know off the bat...

...can I specify 'AccountIsDisabled' False, create the script without a password, and still have the accounts enabled after being imported?

Also, can I exclude the column 'Path' from my csv file but have the DN path for the OU on the script? I am not sure if this makes sense, what I am trying to do here is minimize the number of columns that I will need to include on the csv file.

Thank you!!
You would use -Enabled $True and you can definitely have the OU in the script instead. I just put it in the CSV file incase you needed to create users in different OU's

Import-Module ActiveDirectory
$newusers = Import-CSV "C:\UserstoImport.csv"
ForEach ($user in $newusers) {
New-ADUser `
-SamAccountName $user.SamAccountName `
-Name ($user.FirstName + " " + $user.LastName) `
-DisplayName ($user.FirstName + " " + $user.LastName) `
-GivenName $user.FirstName `
-Surname $user.LastName `
-Enabled $true `
-Path "OU=Users,OU=MySite,DC=mycomain,DC=com"
}

Open in new window

...can I specify 'AccountIsDisabled' False, create the script without a password, and still have the accounts enabled after being imported?
You would use the -Enabled $true to enable the accounts without a password.

Also, can I exclude the column 'Path' from my csv file but have the DN path for the OU on the script? I am not sure if this makes sense, what I am trying to do here is minimize the number of columns that I will need to include on the csv file.

Yes you can do this also. If you want all of the users to go into the same OU then you can specify the complete path and not use the $Path variable.

Will.
ASKER CERTIFIED SOLUTION
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
: D
Joshua and Will, thank you for the help!