Active directory LDAP Query question.

Gohaan

Limit Breaker
Adventurer
Joined
Mar 14, 2008
Messages
614
Location
Ontario, Canada
Main Job
Monk-Male
Secondary Job
Thief-Male
Third Job
BlackMage-Male
Server
Quetzalcoatl
FFXIV
Gohaan
I need to ensure that all the telephone numbers in Active directory are all in the same format. I am not going through 1 by 1. What is the syntax to see if the greater or less than a certain amount of characters?
 
I'm sure you could find a script to strip out the telephone fields from AD accounts into a CSV file.

I'd have to look around, but I don't have the time atm, but I'll direct you to the bible of Windows Server scripting:

Hey, Scripting Guy! Archive
 
There are several options for modifying the phonenumber attribute directly from the ldap query, however ldap functionality is limited in the number of operators you can utilize for retrieval.

You can combine ldap and VBS to perform the type of searching and updating you are looking for, however I don't know it off the top of my head.

I will be on with work after Einherjar, and do a little testing for you. The easiest method would be to export Username, phonenumber from a standard LDAP query and import into excel. From there you could organize as needed and use another snippet to update them a lot quicker, however it will still be 1by1 in the code that you run.

If you are looking to make a blanket change (say adding (+1) or '9' to all the numbers) for consistency or to enable direct dialing from AD with an LDAP enabled phone system, this can be done pretty easily as you are updating all records with the same info.

Either way, I will try out the code I jotted down today. Don't want to post something that I didn't test. It will be 2 pieces, one to extract the data and one to update the data. If you would like something different, let me know.
 
I found the script I was looking for.

Code:
Wscript.StdOut.Write "Enter a Group Name: " 
strGroupname = Wscript.StdIn.ReadLine 
 
If strGroupname = "" Then 
    Wscript.Quit 
End If 
 
Wscript.Echo "File will be stored in this working directory" 
Wscript.StdOut.Write "Enter a filename: " 
strLogfilename = Wscript.StdIn.ReadLine 
 
If strLogfilename = "" Then 
    Wscript.Quit 
End If 
 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objLogFile = objFSO.CreateTextFile(strLogfilename, _ 
    ForWriting, True) 
 
Set objGroup = GetObject _ 
    ("LDAP://cn=" & strGroupname & ",ou=OU_name,dc=domain_controller_name,dc=domain_tier,dc=top_level") 
 
For Each Member in objGroup.GetEx("member") 
    objLogFile.Write Member 
    objLogFile.WriteLine 
Next 
 
objLogFile.Close
Try a variation on this one. As it stands, all this exports is the username in long format, and exports them into a CSV file. I'm sure if you prod around, you can find the LDAP value for the telephone number(s) and export them as well.

Good luck ^^
 
It's not difficult Gohaan - just a little tedious, but rewarding, best of luck :)
 
Back
Top