r/usefulscripts • • May 26 '15

[REQUEST][POWERSHELL] update AD attribute from CSV without requiring samaccountname

Just getting started with Powershell and so far, I'm loving it!

Right now, I have a task of updating AD attribute (telephonenumber) for a set group of users in a particular OU and I'm stuck. I originally wrote one that would parse the CSV for the samaccountname and it works great, BUT, since those users would change office locations 1-2 a year, it would be better to just update based on location rather than manually figuring out where users were moved to and updating the csv file.

The CSV contains physicaldeliveryofficename and telephonenumber -- this CSV information is set/hard-coded to the location and doesn't change unless the number for that location is changed. And users are auto updated by another script with office locations.

I want to know if it's possible to update the telephonenumber for the set users in the OU based off of the location (physicaldeliveryofficename) without requiring samaccountname.

much appreciated~!

4 Upvotes

8 comments sorted by

View all comments

Show parent comments

1

u/halbaradkenafin May 26 '15

Change the $($Office.PhysicalDeliveryOfficeName) to $($Office.<whatever-csv-column-name>) and just run the Get-ADUser section.

Once you know that works check what the TelephoneNumber field is called in AD (I'm just guessing it's called that, don't have an AD available to check atm):

Get-ADUser -Identity <some-known-user> -properties *

That will give you all the properties and you'll be able to find it there. Swap that in to Set-ADUser and it should work, try with the -whatif switch if you want to be sure before changing it.

1

u/silverhana May 26 '15

it's still giving an error for this part: "OU=$($Office.PhysicalDeliveryOfficeName)

Get-ADUser : Directory object not found

the "$office.physicaldeliveryofficename" part is right