Solved

Update Users Properties in Active Directory by Script and CSV

Posted on 2015-02-08
6
52 Views
Last Modified: 2015-03-19
Dear All,

I’m looking for a help to update all users properties and date in active directory (phone number, mobile number, department, office ... etc), i'm looking for help to find a script which can do this.


Please help.

Thanks
0
Comment
Question by:Rhala
6 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40596804
Do you have the users sAMAccountName in the CSV? Construct the csv file like below...

CSV Example
sAMAccountName    department    Office          phone              mobilephone
dsmith                         accounting      highbury    xxx-xxx-xxxx   xxx-xxx-xxxx
etc....

Import-module activedirectory
$Changes = import-csv "c:\yourcsvhere.csv"
foreach ($User in $Changes) { 
$User.sAMAccountName
$User.department
$User.Office
$User.phone
$User.mobilephone
Set-Aduser -Identity $User.sAMAccountName -Department $User.department -Office $User.Office -OfficePhone $User.phone -MobilePhone $User.mobilephone
}

Open in new window


That should do it.

Will.
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 40596809
something along this line will work
update-users.ps1
$users = import-csv -path c:\scripts\update-users.csv
foreach ($user in $users){
Set-ADUser -Identity $user.samaccountname> -MobilePhone $user.mobile -OfficePhone $user.officephone
}

Open in new window

update-users.csv
samaccountname,mobile,officephone
johndoe,123-456-7890,789-123-1234x1234

Open in new window


https://technet.microsoft.com/en-us/library/hh852287.aspx
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 40597312
Not all properties are available with Set-AdUsers directly, but the common ones are. If you have difficulties to find the parameter names, post back with the details.
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

Author Comment

by:Rhala
ID: 40600431
thanks all,

does what you mentioned will overwrite what exists in AD?

also, is there a list of all AD properties in one CSV file which i can include all info and them update it one time
0
 

Author Comment

by:Rhala
ID: 40600456
Hi All,

I found the below script which it seems it can do some work:
https://gallery.technet.microsoft.com/scriptcenter/Feeding-data-to-Active-0227d15c/view/Discussions#content

i need to ask how i can add or delete prosperities to the CSV file and then update the script based on that
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40637153
The script in the link is using Quest tools to do the work. This can be done the same without Quest if the ActiveDirectory PowerShell module is available. But:

1. You never want to have a CSV containing all possible AD attributes. You focus on a few, e.g. all address related ones. Anything else is getting far off course, prone to errors, impractical, or in short a mess.

2. Most AD attributes may not be set to empty/null, and trying to do so will end in error messages stopping from applying any change. A script offering to set attributes optionally needs to check for values, and use a different syntax for deleting or replacing (combined) or adding (combined) setting values.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now