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!
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!