Solved

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

Posted on 2007-04-10
6
486 Views
Last Modified: 2012-03-22
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.
0
Comment
  • 3
  • 3
6 Comments
 
LVL 30

Expert Comment

by:LauraEHunterMVP
ID: 18884708
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.
0
 

Author Comment

by:Yann de Champlain, PMP
ID: 18887598
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"
0
 
LVL 30

Expert Comment

by:LauraEHunterMVP
ID: 18888524
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
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:Yann de Champlain, PMP
ID: 18889617
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.
0
 
LVL 30

Accepted Solution

by:
LauraEHunterMVP earned 500 total points
ID: 18890171
The following script assumes that you want to make this change for every single user in your domain.  If you want to run it on a single OU as a test, just change the DN in the first line from "dc=company,dc=com" to something like "ou=TestOU,dc=company,dc=com"

Option Explicit

dim objParent, objUser, strCurrentPhone,strNewPhone

set objParent = GetObject("LDAP://dc=company,dc=com")
objParent.Filter = Array("user")
for each objUser in objParent
  strCurrentPhone = objUser.Get("homePhone")
  strNewPhone = Replace(strCurrentPhone," (0)","")
  objUser.Put "homePhone", strNewPhone
next

set objParent = nothing
0
 

Author Comment

by:Yann de Champlain, PMP
ID: 18891394
Tanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

The 6120xp switches seem to have a bug when you create a fiber port channel when you have a UCS fabric interconnects talking to them.  If you follow the Cisco guide for the UCS, the FC Port channel will never come up and it will say that there are n…
More or less everybody in the IT market understands the basics of Networking, however when we start talking about Storage Networks, things get a bit dizzier, and this is where I would like to help.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now