• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 54
  • Last Modified:

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

UserPrincipalName
-GivenName
-Surname
-Name
-DisplayName
-Description
-Department
-Title
-StreetAddress
-PostalCode
-Office
-OfficePhone
-Manager
-Email
-City
-State
-Company

Thanks you for your help
0
gd6627
Asked:
gd6627
  • 4
  • 2
  • 2
  • +1
2 Solutions
 
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 $user.name `
-DisplayName $user.displayname `
-Description $user.description `
-Department $user.department `
-Title $user.title `
-StreetAddress $user.streetaddress `
-PostalCode $user.postalcode `
-physicalDeliveryOfficeName $user.office `
-telephoneNumber $user.OfficePhone
-Manager $user.manager `
-mail $user.email `
-l $user.city `
-St $user.state `
-Company -$user.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 SMTP:primaryaddress@domain.com 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.
0
 
Paul MacDonaldDirector, Information SystemsCommented:
Here is a script from TechNet - which I have not used - that should do what you need.
0
 
Kevin StanushApplication DeveloperCommented:
You can mass update Active Directory using Hyena.  Here is a video that shows how its done:

https://www.youtube.com/watch?v=exR2FK7rQ44

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.
0
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

 
gd6627Author Commented:
YEs I do have the samaccountname
0
 
gd6627Author Commented:
Don't you need a license for Hyena?
0
 
Kevin StanushApplication DeveloperCommented:
Yes, Hyena needs a license after the initial free 30-day eval period.
0
 
gd6627Author Commented:
Aaron, How can I also set with I the same script the SMTP address for the email?
0
 
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 <mail@domain.com>.

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 <mail@domain.com> -Replace @{proxyAddresses="SMTP:<mail@domain.com>"} 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 <mail@domain.com> -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.
0
 
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now