Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Updating and changing AD user properties with powershell

$
0
0

Hey guys,

This is my first time posting here. My powershell skills are beginner at best and I am trying to tackle a big project. I have been tasked to update the corporate phone directory for all of our AD users. I managed to do this using a csv file and set-aduser command. It went well until I verified the changes. 406 changes took place but 186 didn't change at all.

 

This is the script I ran

This one grabs the users directory

 

get-aduser

 

 

 

 

 

-filter *-Properties*|selectGivenName,Surname,samaccountname,officephone,mobilephone,

office

This one replaced the information

PS C:\Users\lovethedarkness> import-csv c:\test\exportad2.csv |Foreach-object {set-aduser -identity 
$_.samAccountName -replace @{telephonenumber=$_.Officephone; Mobile=$_.MobilePhone; physi 
calDeliveryOfficeName=$_.office}}

It grabbed the information from my csv and replaced the phones and office location.

However, this script took about 2 hours and im still short 186 people to update.

How can I modify this? The goal in my head is to do the following

-run get-aduser and grab the current information from AD

-create a variable for each string ( officephone, mobilephone, officelocation) to be used for later

-import csv with changes

-create a variable for each string (office phone, mobilephone, officelocation) called $csvvariablename

-compare ADvariable to CSVvariable if they match skip the line, if they don't match take the changes from the csv (maybe a replace command?)

Im stuck on the creating variable from the strings from the get-aduser. How can I do this? I've tried looking into foreach-object, select-object and outvariable but none of these made real sense to me.

Any help would be appreciated! Thanks a bunch!


Viewing all articles
Browse latest Browse all 6937

Trending Articles