Link to home
Start Free TrialLog in
Avatar of Rhala
Rhala

asked on

Update Users Properties in Active Directory by Script and CSV

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
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

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.
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
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.
Avatar of Rhala
Rhala

ASKER

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
Avatar of Rhala

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial