Home

Black Mountain

My Experiment on the Internet

Exchange user info script

Here is the start of a script to pull user information into a tab seperated file from Exchange users.

'==========================================================================
'    NAME: listSMTPinfoDump.vbs
'  AUTHOR: Steven Peck
'    DATE: 11/11/2005

' COMMENT: outputs tab seperated file information
'          FirstName, LastName, DisplayName, EmployeeID, emailAddress
'          Information output to file: c:\output.txt
'MODIFIED:
'
'==========================================================================

On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Today = Month(Now) & "." & Day(Now) & "." & Year(Now)

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

' setup for writing file
Set objWMIService = GetObject("winmgmts:")
Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service")

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.CreateTextFile("C:\" & Today & "ADlist.txt")

' Write file header
objTS.WriteLine "First Name" & vbTab & "Last Name" & vbTab & "Display Name" _
& vbTab & "Employee ID" & vbTab & "Email Address"

' Start of ADSI
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

' Set ADSI query for data
objCommand.CommandText = _
    "SELECT givenName,SN,displayName,employeeID,mail," _
    & "extensionAttribute1" _
    & " FROM 'LDAP://dc=domainname,dc=com' WHERE " _
        & "objectCategory='user'" 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
objTS.WriteLine objRecordSet.Fields("givenName").Value _
& vbTab & objRecordSet.Fields("SN").Value _
& vbTab & objRecordSet.Fields("displayName").Value _
    & vbTab & objRecordSet.Fields("employeeID").Value _
    & vbTab & objRecordSet.Fields("mail").Value _
    & vbTab & objRecordSet.Fields("extensionAttribute1").Value
    objRecordSet.MoveNext
Loop

' close file
objTS.Close

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <blockquote> <img>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Sometimes I get asked, so here it is ... My Amazon.com Wish List

Thought I'd see what this Technorati stuff does.

Login with your OpenID to leave comments
contents copyright Steven Peck - powered by drupal logo