Bulk Modify ipPhone Attribute with PowerShell

Brief History
In one particular domain of mine, the telephoneNumber field in Active Directory had been historically filled out with numbers that included special characters, such as “(555) 555-1234”. The Cisco phone system we purchased, at first, required the numbers to be stored as a string with no special characters (eg: 5555551234). Now, this normally wouldn’t be a problem – in theory, we could just update the telephoneNumber field stripping all special characters out. However, we had various other pieces of software that relied upon the telephone number field having those special characters included.

D’oh. No big deal, though. The ipPhone attribute can be used for just this scenario, and fortunately the Cisco phone system we purchased can also be pointed to that attribute. So I made a script that does just that:

updateIPphone-10digit

The above script will update the ipPhone field of all objects in Active Directory so that it is the same as the telephoneNumber field, minus special characters – eg: telephoneNumber stays as “(555) 555-1234” but ipPhone will get populated with “5555551234”

Later on, however, our vendor required that the ipPhone field be extension only, (eg: 5555). I’m not clear on the reasoning behind this – something to do with Jabber clients I think, but the orders came down that the ipPhone attribute had to be updated once again. Thus, I made the following script:

updateIPphone-extension.ps1

The above script will update the ipPhone field of all objects in Active Directory so that it is the same as the last 4 digits of the telephoneNumber field.

We then ran into a scenario wherein the number we stored in active directory wasn’t necessarily a number that we needed just a 4-digit extension for (for example, an object in AD with a cell phone number instead of a phone number capable of being reached at a 4-digit extension), so I created the following script.

updateIPphone-combined

The above script will update the ipPhone field of all objects in Active Directory so that if telephoneNumber matches a specific area code and prefix (eg: “(555) 555”) that it will update ipPhone with the last 4 digits only (eg: 1234), and if it doesn’t match that area code and prefix, it will update the ipPhone field with the entire 10 digit string minus special characters (eg: 5555551234).

Since all of the phone numbers assigned to our campus began with “(555) 555”, all the Active Directory objects that began with that particular string had just the last 4 digits populated in ipPhone. For any numbers that didn’t begin with that string, our objects were updated with the entire 10 digit string without special characters.

You must edit the script and replace “AREACODE” with your area code, and “PREFIX” with your prefix.

Hope this helps someone.


For the latest version of these scripts and more, see my bitbucket repository.

Leave a Comment

Your email address will not be published. Required fields are marked *