on error resume next
Const ADS_PROPERTY_APPEND = 3
Const ADS_PROPERTY_DELETE = 4
Dim qQuery, objConnection, objCommand, objRecordSet, obj
Dim oRootDSE, strDomain
Set oRootDSE = GetObject("LDAP://rootDSE")
strDomain = oRootDSE.get("defaultNamingContext")
Set fso = Wscript.CreateObject("Scripting.FilesystemObject")
FileName= "C:\file_name.csv"
FileName = InputBox("Please input the destination and name of the file you want to export:","Input Filename","c:\file_name.csv")
strOU = InputBox("Please input the OU you want to PARSE:","Input OU","OU=Computers")
set fsHandle = fso.OpenTextFile (FileName,8,True)
' other categories = computer, user, printqueue, group
qQuery = "
"(objectCategory=user)" & _
";distinguishedName;subtree"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
wscript.Echo "Name, Address"
wscript.Echo "-=-=-=-=-=-=-"
fsHandle.Writeline "Name, Address"
objCommand.CommandText = qQuery
Set objRecordSet = objCommand.Execute
While Not objRecordSet.EOF
Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName"))
arrEmails = objUser.ProxyAddresses
For Each email In arrEmails
If Left(email,4)="SMTP" Then
Wscript.Echo objUser.CN + ", " + email
fsHandle.Writeline objUser.CN + ", " + email
End IF
Next
objRecordSet.MoveNext
Wend
objConnection.Close
fsHandle.Writeblanklines 1
fsHandle.close
set fso = Nothing
set objShell = wscript.createobject("wscript.shell")
MsgBox "Your report has been generated! Click OK to view in Notepad",48,"Success!"
objShell.Run "notepad " + FileName
No comments:
Post a Comment