Reputation: 650
I am trying to edit the formatting of a group of user's phone numbers in AD. Specifically, replacing '-' characters with ' '. However, I do not seem to be able to access the existing phone number, which I need to do to replace the characters. I understand the -OfficePhone flag under Set-ADUser sets the telephoneNumber attribute, which seems to be working and the telephoneNumber attribute is there with the expected value in Attribute Editor as well. However when I try to access $user.telephoneNumber
it comes up blank.
Here is my code, commented with what works/what doesn't and some behaviors:
foreach ($user in $users) {
# Works. Prints out various basic attributes of user
Write-Output $user
# Doesn't work. Prints blank
Write-Output $user.telephoneNumber
# Works
Set-ADUser -Identity $user -OfficePhone '555555555'
}
Upvotes: 2
Views: 5437
Reputation: 2415
As AdminOfThings has stated, you need to make the property accessible. You do this by using the -Properties
parameter on the Get-ADUser
command. Here is an example:
Get-ADUser -Identity USER_NAME -Properties TelephoneNumber
If you wanted to get all the properties back, you can use:
Get-ADUser -Identity USER_NAME -Properties *
Upvotes: 2