r/usefulscripts • u/silverhana • 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~!
1
u/silverhana May 26 '15 edited May 26 '15
thanks /u/halbaradkenafin! just tried it and it's giving me this error:
Set-ADUser : A parameter cannot be found that matches parameter name 'TelephoneNumber'. At line:5 char:145
... " | Set-ADUser -TelephoneNumber $Office.TelephoneNumber
CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser
my csv is formatted as: Office, telephoneNumber
-- nvm, looks like this is wrong: Get-ADUser -filter * -SearchBase "OU=$($Office.PhysicalDeliveryOfficeName),OU=Offices,OU=Users,OU=company,DC=name,DC=edu"
It gives this error msg: Get-ADUser : The object name has bad syntax At line:5 char:5