When you manage phone book information in active directory sometimes there is a need to reformat data to keep in consistent or just to make it look good. Today I was given a task to deploy new signatures throughout whole organisation. During tests I discovered that telephone number is badly formatted like:

  • +xx xxx xxx xxx(desired state)
  • +xxxxxxxxxx
  • xxxx xxxx
  • etc.

In other words – total mess.

To avoid changing dozens phone numbers manually and most likely making few mistakes I crated very simple script that performs following tasks:

  • get all users from ad that have telephonenumber attribute set
  • get rid of spaces
  • get rid of national prefix
  • insert spaces
  • insert prefix
  • update user in Active Directory

Script is below, happy updating!