Solved

Update Users Properties in Active Directory by Script and CSV

Posted on 2015-02-08
6
51 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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…

758 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

17 Experts available now in Live!

Get 1:1 Help Now