Set the user properties in AD in bulk

I need a powershell script that sets the user properties in AD based of  off a csv import file. The csv file will have thefollowing headers . The script should go thru each row and update the specific user in the Ad user ADUC


Thanks you for your help
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aaron GuilmetteTechnology Solutions ProfessionalCommented:
You need a way to be able to identify your existing users.  Do you have an existing "known good" attribute that you can use to identify existing users?  For example, something immutable that won't be changing, such as sAMAccountName?

If you can put it in another column next to the user they reference, your job becomes immeasurably easier.

I'm going to assume you do have that information and that you can fill in the appropriate column in your existing CSV.  From there:

Import-Module ActiveDirectory
$Users = Import-Csv UserData.csv
Foreach ($user in $users)
{ Set-ADUser -identity $user.samaccountname `
-givenName $user.GivenName `
-sn $user.Surname `
-UserPrincipalName $user.userprincipalname `
-Name $ `
-DisplayName $user.displayname `
-Description $user.description `
-Department $user.department `
-Title $user.title `
-StreetAddress $user.streetaddress `
-PostalCode $user.postalcode `
-physicalDeliveryOfficeName $ `
-telephoneNumber $user.OfficePhone
-Manager $user.manager `
-mail $ `
-l $ `
-St $user.state `
-Company -$ }

There are some fields that require different kinds of data.  For example, 'manager' is actual a reference to another Active Directory user object, so you need to specify a value that that can be resolved.  If possible, put the samAccountName of the user's manager in the manager column.  If you don't have the sam account name, you'll need to query AD a value to put there.  I also updated the fields with the proper attribute names.

If you have Exchange on-premises, you'll want to manage the mail attribute via Exchange instead of from ADUC.  Exchange uses the proxyAddresses array as well, and sets the value as the value for the mail attribute.  If you set it manually, you may conflict with an existing user, so be sure to make sure everyone has unique addresses.  AD powershell does not check uniqueness for any values aside from samAccountName and CN.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Paul MacDonaldDirector, Information SystemsCommented:
Here is a script from TechNet - which I have not used - that should do what you need.
Kevin StanushApplication DeveloperCommented:
You can mass update Active Directory using Hyena.  Here is a video that shows how its done:

You can match on any unique attribute, and also update the manager using another matching field.  Users can also be added to one or more groups while being created.
Discover the Answer to Productive IT

Discover app within WatchGuard's Wi-Fi Cloud helps you optimize W-Fi user experience with the most complete set of visibility, troubleshooting, and network health features. Quickly pinpointing network problems will lead to more happy users and most importantly, productive IT.

gd6627Author Commented:
YEs I do have the samaccountname
gd6627Author Commented:
Don't you need a license for Hyena?
Kevin StanushApplication DeveloperCommented:
Yes, Hyena needs a license after the initial free 30-day eval period.
gd6627Author Commented:
Aaron, How can I also set with I the same script the SMTP address for the email?
Aaron GuilmetteTechnology Solutions ProfessionalCommented:
It becomes really detailed if you're setting it with Exchange.  If you aren't managing Exchange on-premises, you can just use the Set-ADUser -identity <samaccountname> -mail <>.

If you're using Exchange, you have to check for the existence of the proxyAddresses attribute; if it's blank, you can simply run:

Set-ADUser -Identity <samaccountname> -mail <> -Replace @{proxyAddresses="SMTP:<>"} to set both properties.

If you already have Exchange installed, I'd recommend using the Exchange Management Shell to set that address (Set-Mailbox -identity <samaccountname> -primarysmtpaddress <> -emailaddresspolicyenabled $false).  If the proxy address isn't already in the proxyAddresses array, the Set-Mailbox cmdlet will add it and set it as primary.
gd6627Author Commented:
Aaron I forgot how do I incorporate the users home drive parameter into the script ? if I use the home folder connect option I like to know how to set the Shared folder letter Like (H) for home then the server path and the folder home drive name based on the users samaccount name
like  this

Connect H: \\servername\home\samaccountname
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.