We help IT Professionals succeed at work.

LDAP query to generate phone and mail list

I need to generate a text file with the following fields from my W2003 AD:

User logon name
E-mail (the one from the General tab in AD U&C)
Mobile

Filters:
The users should search AD from root with all sub OUs.
Should be member of a specific _security group_
Should be active (not disabled)

I haven't done this for years and hopefully someone has a template for this.

Thanks in advance!
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Hi, try this VBScript.

Regards,

Rob.
strOutput = "UserDetail.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strOutput, True)
objFile.WriteLine & """Username"",""Email"",""Mobile"""
Const ADS_UF_ACCOUNTDISABLE = 2
Set objGroup = GetObject("CN=GroupName,OU=Offices,DC=domain,DC=com")
For Each objMember In objGroup.Members
	If LCase(objMember.Class) = "user" Then
		Set objUser = GetObject("LDAP://" & objMember)
		intUAC = objUser.Get("userAccountControl")
		If intUAC And ADS_UF_ACCOUNTDISABLE Then
			' Account is disabled
		Else
			objFile.WriteLine """" & objUser.samAccountName & """,""" & objUser.mail & """,""" & objUser.mobile & """"
		End If
	End If
Next
objFile.Close
WScript.Echo "Finished. Please see " & strOutput

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.