Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modify VB Script to List AD users but skip disabled users?

Status
Not open for further replies.

bob000

Programmer
Aug 23, 2001
20
US
I have this VB script which works fine but lists all AD users. How can I change it to skip disabled users?
Thanks,
Bob Mendgik

rem Query Active Directory and list email, Last name, first name, phone, title, dept

dim filesys, filetxt
Const ForWriting = 2
Const OutputFile = "c:\ADEmailName.txt"
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile(OutputFile, ForWriting, True)

Dim strTargetOU
strTargetOU="CN=users,DC=<your domain>,DC=org"

Set oTargetOU = GetObject("LDAP://" & strTargetOU)
oTargetOU.Filter = Array("user")

For each usr in oTargetOU

if instr(usr.SamAccountName, "$") = 0 then
if usr.sn <> "" then
vLast = usr.sn
vFirst = usr.GivenName
vphone = usr.telephoneNumber
vtitle = usr.title
vdepartment = usr.department
vmail = usr.mail
if vmail <> "" then
if VLast = "" then VLast = "MissingLastName"
if vFirst = "" then vFirst = "MissingFirstName"
if vphone = "" then vphone = "MissingPhoneNumber"
if vtitle = "" then vtitle = "MissingTitle"
if vdepartment = "" then vdepartment = "MissingDepartment"
vrecord = vmail + ","+ vLast + "," + vFirst + "," + vPhone + "," + vTitle + _
vdepartment

filetxt.WriteLine vrecord
end if
end if
end if

Next


filetxt.Close

WScript.Echo "Report " + OutputFile + " complete!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top