• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

i want to add a country code to our phone numbers in active directory

MY boss wants me to add the country area code before the numbers in our active directory.  Is there an easy way to do this besides going into each user and updating it manually?

help?

I am running active directory on windows 2000 and have each country in it's own OU.
0
YankeeFan03
Asked:
YankeeFan03
  • 3
1 Solution
 
mdiglioCommented:
Hello,
Here is some code that should work for you.
If you have questions just ask and I can provide more details as to what it is doing.

Before running this you must change a few lines.
The lines you need to change are all commented by using '!!!!!!

Error control is turned off

Copy and paste the code into notepad and save it with a .vbs extension.
( If you have VB6 it will go into a project by adding the Microsoft ActiveX Data Objects 2.7 library reference)

run it as a user that has the appropriate rights to make these updates

You will have to make 2 changes to the script for every ou you have.
This script will do one ou ( country ) at a time,  and any sub OUs it might have
0
 
mdiglioCommented:
' Begin Copy !!!

'On Error Resume Next
ADS_SCOPE_SUBTREE = 2
ADS_SCOPE_ONELEVEL = 1

Set cnn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
cnn.Provider = "ADsDSOObject"  
cnn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cnn
cmd.Properties("Page Size") = 1000
cmd.Properties("Timeout") = 30

'!!!! Change this line depending upon how far down the starting OU you
'!!!! would like to enumerate....ADS_SCOPE_ONELEVEL or ADS_SCOPE_SUBTREE... **see Below


cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE  
cmd.Properties("Cache Results") = True

'this will enumerate all users and grab their DN and current phone number
'!!!!you will have to change the 2nd line to match your OU Design!!!!!
    cmd.CommandText = "select distinguishedname, telephonenumber from 'LDAP://" & _
    " ou=THeCountry,ou=TOPLevelOU,dc=yourdomain,dc=com' " & _
    "WHERE objectCategory='user'"

Set rs = cmd.Execute
Do While Not rs.EOF

    strDN = rs.Fields("distinguishedname")
    strPhone = rs.Fields("telephonenumber")
   
'!!!!!! change this line for each country
    strPhone = "Insert Country Code Here" & strPhone

    ' example: strPhone = "0123-" & strPhone

    strLDAP = "LDAP:// " & strDN & ""
    Set x = GetObject(strLDAP)
    x.Put "telephonenumber", strPhone
    x.SetInfo

    rs.MoveNext
   
Loop

msgbox "Done"

' **using the example above of the fake domain with the 2 OUs...leaving the ADS_SCOPE_SUBTREE will enumerate all ous beneath
' **the ou I called 'THeCountry'. changing it to ADS_SCOPE_ONELEVEL will only enumerate the users in that ou
' From your question it sounds like you do can jsut leave it as ADS_SCOPE_SUBTREE


' End copy !!!
0
 
YankeeFan03Author Commented:
will do thanks.  do i need to run this on the server?
0
 
mdiglioCommented:
no, you can run it from your workstation.
The more important part is the user who runs it.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now