Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Create up update AD user account

Create up update AD user account

Create up update AD user account

I've been working on creating a new script to further automate our user on-boarding process and I've run into something of a wall. I want to be able to populate different aspects of a new user account with address details, move to a specific OU, etc. based on that users physical location. So the way this works is I'll either get a csv file from HR with the users location information but i also have code i can uncomment to prompt for the same details for someone running the script without the csv file.

For address details, I've got a csv file: office,streetaddress,city,state,zip. So based on the office a user will work from, I want to populate variables based on that location. So I am trying to do something like this:

$addressFile = "\\path-to-csv\addresses.csv"
$office = "Okemos"
Import-Csv $addressFile|? Office -eq $office | Where-Object {

set-aduser -identity $username -replace @{"streetAddress"=$streetaddress}
set-aduser -identity $username -replace @{"postalcode"=$zipcode}
set-aduser -identity $username -replace @{"Country"=$Country}
set-aduser -identity $username -city $addressfile.city
set-aduser -identity $username -replace @{"stateorprovence"=$state}


And what's happening is I'm not getting those variables populated with any data.

I want to do the same thing with the OU the account is placed in as well. Same principal, just different data. The OU is based on department and location. So I created a csv with all possible combinations of office and department and their associated OU. For example, if a user will be in St. Louis Sales, the OU the account goes in is for that specific office/department. The reason for this is mostly application of policy.

It is entirely possible that I am approaching this wrong and shouldn't be using a csv but rather excel docs or possibly even a sql db (though I feel that's overkill for something like this), however, I'd appreciate any guidance on this please. Once i have the theory down for what I'm wanting to accomplish i can take it from there.

Thanks all.

RE: Create up update AD user account

I would import the entire address file. If you're running the import from a file supplied by HR, you'll need to reference it multiple times, so it would be more efficient to get it once and repeatedly search the import for the data you need. If you're running it without the file from HR you can then push the array to a list and have the user pick the location from that.

Are all your users in the same OU or do you have one OU per location.

We have multiple OUs. So I have a list of locations from which the admin running the user creation script can pick. Each location has an associated OU. Each OU has the address, city, state (if applicable), country (c, co, countrycode) and other attributes set. So when the admin picks the location, I pull all of attributes directly from the OU and apply them to the new user.

Light travels faster than sound. That's why some people appear bright until you hear them speak.

RE: Create up update AD user account

By importing the entire file, do you mean use import-csv? Or do think it better to go a step further and create an array with that data?

My users are scattered about in multiple OU's. Like you, our users are in specific OU's based on their location and then sub containers based on department.

RE: Create up update AD user account

Yes. Import-Csv creates an array. The first row of the csv file is the attribute names.

CODE -->

Example of file
row 1: FirstName,MiddleInitial,LastName,Office,Street,City,State,Zip
row 2: John,Q,Public,San Francisco,1234 Main Street,San Francisco,CA,94107 

CODE -->

$users = Import-Csv <path2file>
forach ($user in $users)
   $fname = $user.FirstName
   $lname = $user.LastName
   <Create User>

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close