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'
}