Link to home
Start Free TrialLog in
Avatar of Yann de Champlain
Yann de ChamplainFlag for Canada

asked on

How-to reformat all the phone numbers in Active Directory?

I need a solution to search and replace information in the phone fields in Active Directory.

The current format of the number cause problem when it is synchronized with PDAs/Smartphone.

I need to reformat all the phone numbers to remove "(0)".

Is there an easy solution?

Thanks.
Avatar of LauraEHunterMVP
LauraEHunterMVP
Flag of United States of America image

If I'm understanding you correctly, you have phone numbers listed in your users' properties sheets as:

(0)215-555-1212

And you need it to be formatted as

215-555-1212

?

How many users are we talking about?

If each phone number is formatted -the same way-, this is basic string manipulation that can be done relatively easily using a script.

If the phone number formatting is all over the map, IE, some are (0) 215-555-1212, some are 0-215-555-1212, some are (215) 5551212, it's going to be much easier to just create an Excel spreadsheet containing each user and their phone number and just manually reload them.  

Either way, moving forward you'll need to either enforce this procedurally with whomever creates your user accounts, or else invest in some sort of account provisioning software that can enforce the formatting rules that you need.
Avatar of Yann de Champlain

ASKER

I am Business Project Manager.  The people in charge of the AD are trying To Bul...t me saying that it is not possible. I know they're wrong. So I need to bring the solution to make them move.

We are talking of about 2500 user I would say. maybe more.   As far as I know, we only need to remove "(0)" all the numbers seems to be in a clean format.  So, I would not really need to user RegEx formlua.  But the problem is the tool, util to perform this modification. This is a company with a lot of security rules and standards.

This is Europeen number so it look like "+33 (0)1 11 22 33 44"
The following VBScript will take a single user account and modify its telephone number properties - I don't have a script handy that'll do precisely what you're looking for (query AD for all user objects and clean up the phone number), but let me know if you need it and I can put it together.

Const ADS_PROPERTY_UPDATE = 2
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
 
objUser.Put "homePhone", "(425) 555-0100"
objUser.Put "pager", "(425) 555-0101"
objUser.Put "mobile", "(425) 555-0102"
objUser.Put "facsimileTelephoneNumber", "(425) 555-0103"  
objUser.Put "ipPhone", "5555"
objUser.SetInfo

As for actually cleaning up an existing entry, it's a simple string manipulation function in VBScript.

[1] Retrieve the existing entry in a variable called currentPhone:

[2] Run a string replacement on currentPhone: Replace(currentPhone, " (0)", "")

[3] Set currentPhone as the user's new phone attribute: objUser.Put "homePhone", currentPhone
I think it would do it yes.
Thank you.

But indeed, I would need a clean and a little more complete code.
I suppose currentPhone would be the var in a loop to replace all the phone number fields?

Thanks for your code.  The completed version of this will do the trick.
ASKER CERTIFIED SOLUTION
Avatar of LauraEHunterMVP
LauraEHunterMVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tanks!