Const ForWriting = 2 ' creats a constant for writing to file
Const Forappending = 8 ' creates a constant for appending to file
OutputFile = "InventoryUsers.csv" ' Output file with server details
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Set objInputFile = objFSO.OpenTextFile(InputFile,1,FALSE) ' opens text file object
Set objOutputFile = objFSO.OpenTextFile(OutputFile, forWriting, True) ' opens output file for writing
objOutputFile.WriteLine "Account name" & "," & "Alternate Recipient"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
";" & _
"(&(objectCategory=person)(objectClass=user));" & _
"ADsPath;subtree"
Set objRecordSet = objCommand.Execute
While Not objRecordset.EOF
strADsPath = objRecordset.Fields("ADsPath")
Set objUser = GetObject(strADsPath)
WScript.Echo "Processing ....." & vbtab & objUser.samAccountName
objOutputFile.WriteLine objUser.samAccountName & "," & objUser.altRecipient
objRecordset.MoveNext
Wend
Wscript.Echo objRecordSet.RecordCount & " Users Checked"
objConnection.Close
|