• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 606
  • Last Modified:

Enumerating members of Active Directory Groups

I am looking to write a script that will enumerate a list of users that have their mailboxes on a certain exchange server in my active directory structure.

The overall data that I need pulled for each user is their username, their mailbox store, and their department.

Any help with this would be appreciated.
-Parker
0
Erdrick33
Asked:
Erdrick33
  • 2
1 Solution
 
bsharathCommented:
Check this script this will get you what you want and much more...But dout about the department

' Save as GetStoreLimits.vbs
'
' Retrieves information relating to Mailbox Sizes. Must be run as Exchange Administrator and must be run from a
' machine with the Exchange System Tools installed. Only compatible with Exchange 2003.
'
' Author: Chris Dent
' Last Modified: 04/05/2006

Option Explicit

'
' Functions
'

Function FormatGUID(arrGUID)
      Dim strGUID, strTemp
      Dim i

      For i = LBound(arrGUID) To UBound(arrGUID)
            strTemp = strTemp & Hex(AscB(MidB(arrGUID, i + 1, 1)) \ 16) &_
                  Hex(AscB(MidB(arrGUID, i + 1, 1)) Mod 16)
      Next

      ' Reversed Pairs

      i = 0
      strGUID = "{"
      Do Until i = 8
            strGUID = strGUID & Mid(strTemp, 7 - i, 1)
            strGUID = strGUID & Mid(strTemp, 8 - i, 1)
            i = i + 2
      Loop
      strGUID = strGUID & "-"
      Do Until i = 12
            strGUID = strGUID & Mid(strTemp, 19 - i, 1)
            strGUID = strGUID & Mid(strTemp, 20 - i, 1)
            i = i + 2
      Loop
      strGUID = strGUID & "-"
      Do Until i = 16
            strGUID = strGUID & Mid(strTemp, 27 - i, 1)
            strGUID = strGUID & Mid(strTemp, 28 - i, 1)
            i = i + 2
      Loop
      strGUID = strGUID & "-"

      ' Normal Pairs

      For i = 17 to 20
            strGUID = strGUID & Mid(strTemp, i, 1)
      Next
      strGUID = strGUID & "-"
      For i = 21 to 32
            strGUID = strGUID & Mid(strTemp, i, 1)
      Next
      strGUID = strGUID & "}"
      FormatGUID = strGUID
End Function

Function GetForestContexts
      ' Returns a array containing all Domains (Distinguished Name) in the active Forest

      Dim objRootDSE, objForestRoot
      Dim strForestRoot, strSubDomain
      Dim arrDomainDNs(), arrTemp

      Set objRootDSE = GetObject("LDAP://RootDSE")
      strForestRoot = objRootDSE.Get("rootDomainNamingContext")
      Set objForestRoot = GetObject("LDAP://" & strForestRoot)

      ReDim Preserve arrDomainDNs(0)
      arrDomainDNs(0) = strForestRoot

      ' Rebuild Domains List removing the DNS and Configuration contexts

      arrTemp = objForestRoot.Get("subRefs")
      For Each strSubDomain in arrTemp
            If (InStr(strSubDomain, "DnsZones") = 0) And (InStr(strSubDomain, "Configuration") = 0) Then
                  ReDim Preserve arrDomainDNs(UBound(arrDomainDNs) + 1)
                  arrDomainDNs(UBound(arrDomainDNs)) = strSubDomain
            End If
      Next

      Set objForestRoot = Nothing
      Set objRootDSE = Nothing
     
      GetForestContexts = arrDomainDNs
End Function

Function ConvertToDNS(arrDomainDNs)
      ' Converts Distinguished Names to DNS Names

      Dim strDN, strDomainName
      Dim arrDomainNames()
      Dim i
     
      i = 0
      For Each strDN in arrDomainDNs
            ReDim Preserve arrDomainNames(i)
            strDomainName = Replace(strDN, ",DC=", ".")
            strDomainName = Replace(strDomainName, "DC=", "")
            arrDomainNames(i) = strDomainName
            i = i + 1
      Next
     
      ConvertToDNS = arrDomainNames
End Function

Function GetExchangeServers(strAdminGroup)
      Dim objRootDSE, objExchangeService, objContainer, objAdministrativeGroups, objAdministrativeGroup
      Dim objServers, objServer
      Dim strOrganisationPath, strAdminGroupDisplayName, strAdminGroupName
      Dim arrServers()
      Dim i

      Set objRootDSE = GetObject("LDAP://RootDSE")
      Set objExchangeService = GetObject("LDAP://CN=Microsoft Exchange,CN=Services," &_
                  objRootDSE.Get("configurationNamingContext"))
      Set objRootDSE = Nothing
      For Each objContainer in objExchangeService
            If objContainer.Class = "msExchOrganizationContainer" Then
                  strOrganisationPath = objContainer.Get("distinguishedName")
            End If
      Next
      Set objExchangeService = Nothing

      i = 0

      On Error Resume Next
      Set objAdministrativeGroups = GetObject("LDAP://CN=Administrative Groups," & strOrganisationPath)
      For Each objAdministrativeGroup in objAdministrativeGroups
            strAdminGroupDisplayName = "" : strAdminGroupDisplayName = objAdministrativeGroup.Get("displayName")
            strAdminGroupName = "" : strAdminGroupName = objAdministrativeGroup.Get("name")
     
            If LCase(strAdminGroupName) = strAdminGroup Or _
                        (LCase(strAdminGroupDisplayName) = strAdminGroup And _
                        strAdminGroupDisplayName <> "") Or _
                        strAdminGroup = "" Then

                        Set objServers = GetObject("LDAP://CN=Servers," & objAdministrativeGroup.Get("distinguishedName"))
                        For Each objServer in objServers
                              ReDim Preserve arrServers(i)
                              arrServers(i) = objServer.Get("name")
                              i = i + 1
                        Next
                        Set objServers = Nothing
            End If
      Next
      Set objAdministativeGroups = Nothing
      On Error Goto 0
     
      GetExchangeServers = arrServers
End Function

'
' Subroutines
'

'
' Usage & Argument Sorting
'

Sub UsageText
      Dim strMessage

      strMessage = "Usage:" & VbCrLf & VbCrLf
      strMessage = strMessage & "cscript " & WScript.ScriptName & " [-s <Server Name>] " & VbCrLf
      strMessage = strMessage & VbTab & "[-a {<Administrative Group Name>}] [-o] [-r] [-f <Filename>]" & VbCrLf
      strMessage = strMessage & VbTab & "[-l <Filename>]" & VbCrLf
      strMessage = strMessage & VbCrLf
      strMessage = strMessage & VbTab & "-s - List Sizes for Mailboxes on the specified Server" & VbCrLf
      strMessage = strMessage & VbTab & "-a {<Administrative Group Name>} - List Sizes for Mailboxes within" & VbCrLf
      strMessage = strMessage & VbTab & "the specified Administrative Group" & VbCrLf & VbCrLf
      strMessage = strMessage & VbTab & VbTab & "If no Administrative Group is specified the First " & VbCrLf
      strMessage = strMessage & VbTab & VbTab & "Administrative Group is used (even if renamed)" & VbCrLf & VbCrLf
      strMessage = strMessage & VbTab & "-o - List Sizes for Mailboxes within the Entire Organisation" & VbCrLf & VbCrLf
      strMessage = strMessage & VbTab & VbTab & "Organisation wide search may take a long time and includes " & VbCrLf
      strMessage = strMessage & VbTab & VbTab & "searching the Global Catalog for Mail Enabled Users" & VbCrLf & VbCrLf
      strMessage = strMessage & VbTab & "-r - When used with -o this will temporarily Reset the DNS Suffix " & VbCrLf
      strMessage = strMessage & VbTab & "Search List on the Machine running the request to ensure all servers " & VbCrLf
      strMessage = strMessage & VbTab & "within the Forest are accessible." & VbCrLf
      strMessage = strMessage & VbTab & "-f <Filename> - Writes report to a File instead of the Console" & VbCrLf
      strMessage = strMessage & VbTab & "-l <Filename> - Writes a list of Store Usage by Alphabetical Order" & VbCrLf
      strMessage = strMessage & VbCrLf & "Note: This Script must be run as Exchange Administrator for the Servers " & VbCrLf
      strMessage = strMessage & "you wish to query. It will only function with Exchange 2003." & VbCrLf
      WScript.Echo strMessage
      WScript.Quit
End Sub

Sub SortArgv
      Dim objArgv, objRootDSE
      Dim strArgv
      Dim i, j, intServerName, intAdminGroup, intOrganisation, intFileName, intSummaryFile

      Set objArgv = WScript.Arguments
      If objArgv.Count < 1 Then
            UsageText()
      End If

      booServerName = False : booAdminGroup = False : booOrganisation = False
      booResetSuffixes = False : booWriteToFile = False : booWriteSummary = False
      i = 0 : j = 0
      For Each strArgv in objArgv
            i = i + 1
            If LCase(strArgv) = "-s" Then
                  booServerName = True
                  intServerName = i
                  j = j + 1
            End If
            If LCase(strArgv) = "-a" Then
                  booAdminGroup = True
                  intAdminGroup = i
                  j = j + 1
            End If
            If LCase(strArgv) = "-o" Then
                  booOrganisation = True
                  j = j + 1
            End If
            If LCase(strArgv) = "-r" Then
                  booResetSuffixes = True
            End If
            If LCase(strArgv) = "-f" Then
                  booWriteToFile = True
                  intFileName = i
            End If
            If LCase(strArgv) = "-l" Then
                  booWriteSummary = True
                  intSummaryFile = i
            End If
      Next

      If j = 0 Or j > 1 Then
            UsageText()
      End If

      If booServerName = True Then
            If objArgv.Count < (intServerName +  1) Then
                  UsageText()
            Else
                  strServerName = objArgv(intServerName)
            End If
      End If
     
      If booAdminGroup = True Then
            If objArgv.Count < (intAdminGroup +  1) Then
                  strAdminGroup = "first administrative group"
            Else
                  If LCase(objArgv(intAdminGroup)) = "-f" Or LCase(objArgv(intAdminGroup) = "-l") Then
                        strAdminGroup = "first administrative group"
                  Else
                        strAdminGroup = LCase(objArgv(intAdminGroup))
                  End If
            End If
      End If
     
      Set objRootDSE = GetObject("LDAP://RootDSE")
      If booOrganisation = True Then
            strDomainName = objRootDSE.Get("rootDomainNamingContext")
      Else
            strDomainName = objRootDSE.Get("defaultNamingContext")
      End If
      Set objRootDSE = GetObject("LDAP://RootDSE")

      If booResetSuffixes = True And booOrganisation = False Then
            UsageText()
      End If

      If booWriteToFile = True Then
            If objArgv.Count < (intFilename + 1) Then
                  UsageText()
            Else
                  If LCase(objArgv(intFilename)) = "-l" Then
                        UsageText()
                  Else
                        strFileName = objArgv(intFilename)
                  End If
            End If
      End If
     
      If booWriteSummary = True Then
            If objArgv.Count < (intSummaryFile + 1) Then
                  UsageText()
            Else
                  If LCase(objArgv(intSummaryFile)) = "-f" Then
                        UsageText()
                  Else
                        strSummaryFile = objArgv(intSummaryFile)
                  End If
            End If
      End If
     
      Set objArgv = Nothing      
End Sub

'
' Network Adapter
'

Function SetSuffixes(arrDomainNames)
      ' Convert DNS Domain Names to Suffixes and check against IP Configuration
      ' Just works better with these set

      Const REG_HKLM = &H80000002

      Dim objRegistry, objShell
      Dim strKeyPath, strValueName, strSuffixes, strDomainName, strOldSuffixes
      Dim booSetSuffixes

      Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
      strKeyPath = "System\CurrentControlSet\Services\TCPIP\Parameters"
      strValueName = "SearchList"
      objRegistry.GetStringValue REG_HKLM, strKeyPath, strValueName, strOldSuffixes

      For Each strDomainName in arrDomainNames
            If InStr(1, strOldSuffixes, strDomainName, VbTextCompare) = 0 Then
                  booSetSuffixes = True
            End If
      Next

      If booSetSuffixes = True Then
            For Each strDomainName in arrDomainNames
                  strSuffixes = strSuffixes & "," & strDomainName
            Next
            strSuffixes = Right(strSuffixes, Len(strSuffixes) - 1)
            objRegistry.SetStringValue REG_HKLM, strKeyPath, strValueName, strSuffixes
            WScript.Echo strSuffixes
            Set objShell = CreateObject("WScript.Shell")
            objShell.Run "ipconfig /renew"
            Set objShell = Nothing
      End If

      Set objRegistry = Nothing
     
      SetSuffixes = strOldSuffixes
End Function

Sub ResetSuffixes(strSuffixes)
      ' Puts the orignal Suffix Search List back

      Const REG_HKLM = &H80000002

      Dim objRegistry, objShell
      Dim strKeyPath, strValueName, strNewSuffixes

      Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
      strKeyPath = "System\CurrentControlSet\Services\TCPIP\Parameters"
      strValueName = "SearchList"

      objRegistry.GetStringValue REG_HKLM, strKeyPath, strValueName, strNewSuffixes
      If strNewSuffixes <> strSuffixes Then
            objRegistry.SetStringValue REG_HKLM, strKeyPath, strValueName, strSuffixes
            Set objShell = CreateObject("WScript.Shell")
            objShell.Run "ipconfig /renew"
            Set objShell = Nothing
      End If
      Set objRegistry = Nothing
End Sub

'
' AD Query
'

Sub GetADData
      Const ADS_SCOPE_SUBTREE = 2
      Const ADS_UF_ACCOUNTDISABLE = &H2

      Dim objConnection, objCommand, objRootDSE, objRecordSet
      Dim strDisplayName, strUseLimits, strSize, strStore, strMailboxGUID
      Dim strWarnLimit, strQuotaLimit, strServer, strPort, strFields, strEnabled, strMail
      Dim intUAC
      Dim booUseLimits

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

      strPort = "LDAP"
      If booOrganisation = True Then
            strPort = "GC"
      End If
      strFields = "displayName, msExchMailboxGUID, mDBUseDefaults, mDBStorageQuota, " &_
                  "mDBOverQuotaLimit, msExchHomeServerName, userAccountControl, mail"

      Set objRootDSE = GetObject("LDAP://RootDSE")
      objCommand.CommandText = "SELECT " & strFields & " FROM '" & strPort & "://" & strDomainName & "' WHERE " &_
                  "objectCategory='CN=Person,CN=Schema," & objRootDSE.Get("configurationNamingContext") & "'"
      Set objRootDSE = Nothing
     
      objCommand.Properties("Page Size") = 1000
      objCommand.Properties("Timeout") = 600
      objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
      objCommand.Properties("Cache Results") = False
     
      Set objRecordSet = objCommand.Execute
     
      While Not objRecordSet.EOF
            If Not IsNull(objRecordSet.Fields("msExchMailboxGUID")) Then
                  strMailboxGUID = FormatGUID(objRecordSet.Fields("msExchMailboxGUID"))
                 
                  strUseLimits = "" : strWarnLimit = "" : strQuotaLimit = "" : strMail = ""
                  If Not objResults.Exists(strMailboxGUID) Then
                        booUseLimits = objRecordSet.Fields("mDBUseDefaults")
                        strWarnLimit = objRecordSet.Fields("mDBStorageQuota")
                        strQuotaLimit = objRecordSet.Fields("mDBOverQuotaLimit")
                        strServer = objRecordSet.Fields("msExchHomeServerName")
                        strServer = Right(strServer, Len(strServer) - InStr(strServer, "cn=Servers/cn=") - 13)
                        If booUseLimits = True Then
                              strUseLimits = "True"
                        Else
                              strUseLimits = "False"
                        End If

                        intUAC = objRecordSet.Fields("userAccountControl")
                        If intUAC And ADS_UF_ACCOUNTDISABLE Then
                              strEnabled = "No"
                        Else
                              strEnabled = "Yes"
                        End If
                        strMail = objRecordSet.Fields("mail")

                        strDisplayName = objRecordSet.Fields("displayName")
                       
                        If InStr(1, strDisplayName, "SystemMailbox", VbTextCompare) = 0 Then
                              objResults.Add strMailboxGUID, Array(strDisplayName, strUseLimits,_
                                          strWarnLimit, strQuotaLimit, strSize, strServer, strStore, strEnabled, strMail)
                        End If
                  End If
            End If
            objRecordSet.MoveNext
      Wend
     
      objConnection.Close
     
      Set objRecordSet = Nothing
      Set objCommand = Nothing
      Set objConnection = Nothing
End Sub

'
' Exchange Query
'

Sub GetMailboxes(strServerName)
      Const WBEM_RETURN_IMMEDIATELY = &h10
      Const WBEM_FORWARD_ONLY = &h20

      Dim objWMIService, objMailbox
      Dim colMailboxes
      Dim strMailboxGUID, strDisplayName, strUseLimits, strSize, strServer, strStore
      Dim strWarnLimit, strQuotaLimit, strEnabled, strMail

      On Error Resume Next
      Err.Clear
      Set objWMIService = GetObject("winmgmts:\\" & strServerName & "\root\MicrosoftExchangeV2")
      Set colMailboxes = objWMIService.ExecQuery("SELECT * FROM Exchange_Mailbox", "WQL",_
                  WBEM_RETURN_IMMEDIATELY + WBEM_FORWARD_ONLY)

      If Err.Number <> 0 Then
            Exit Sub
      End If
       On Error Goto 0

      For Each objMailbox In colMailboxes
            If InStr(1, objMailbox.MailboxDisplayName, "SystemMailbox", VbTextCompare) = 0 Then
     
                  strMailboxGUID = objMailbox.MailboxGUID

                  If objResults.Exists(strMailboxGUID) Then
                        strDisplayName = objResults(strMailboxGUID)(0)
                        strUseLimits  = objResults(strMailboxGUID)(1)
                        strWarnLimit = objResults(strMailboxGUID)(2)
                        strQuotaLimit = objResults(strMailboxGUID)(3)
                        strServer = objResults(strMailboxGUID)(5)
                        strSize = objMailbox.Size
                        strStore = objMailbox.StoreName
                        strEnabled = objResults(strMailboxGUID)(7)
                        strMail = objResults(strMailboxGUID)(8)
                       
                        objResults.Remove strMailboxGUID
                        objResults.Add strMailboxGUID, Array(strDisplayName, strUseLimits,_
                                    strWarnLimit, strQuotaLimit, strSize, strServer, strStore, strEnabled, strMail)
                  End If
            End If
      Next
     
      Set colMailboxes = Nothing
      Set objWMIService = Nothing
End Sub

Sub CleanResults
      Dim strMailboxGUID

      For Each strMailboxGUID in objResults
            If objResults(strMailboxGUID)(4) = "" Then
                  objResults.Remove(strMailboxGUID)
            End If
      Next
End Sub

Sub WriteResults
      Dim objFileSystem, objFile
      Dim strEcho, strLine, strMailboxGUID, strDisplayName, strUseLimits, strSize, strStore
      Dim strServer, strWarnLimit, strQuotaLimit, strEnabled, strMail
      Dim i, intTotal

      Set objFileSystem = CreateObject("Scripting.FileSystemObject")

      If booWriteToFile = True Then
            Set objFile = objFileSystem.OpenTextFile(strFileName, 2, True, 0)
     
            strLine = "Display Name" & VbTab & "Use Limits Enabled" & VbTab & "Warning Limit" &_
                  VbTab & "Quota Limit" & VbTab & "Size on Server" & VbTab & "Server Name" & VbTab &_
                  "Storage Group" & VbTab & "User Account Enabled" & VbTab & "SMTP Address"
            objFile.WriteLine strLine
      End If
     
      For Each strMailboxGUID in objResults
            strDisplayName = objResults(strMailboxGUID)(0)
            strUseLimits = objResults(strMailboxGUID)(1)
            strWarnLimit = objResults(strMailboxGUID)(2)
            strQuotaLimit = objResults(strMailboxGUID)(3)
            strSize = objResults(strMailboxGUID)(4)
            strServer = objResults(strMailboxGUID)(5)
            strStore = objResults(strMailboxGUID)(6)
            strEnabled = objResults(strMailboxGUID)(7)
            strMail = objResults(strMailboxGUID)(8)
     
            If booWriteToFile = False Then
                  strEcho = strDisplayName & ": "
                  If strUseLimits = "False" Then
                        strEcho = strEcho & "Warning Limit: " & strWarnLimit & " | Quota Limit: " &_
                              strQuotaLimit & " - "
                  End If

                  strEcho = strEcho & "Size: " & strSize & " - Store: " & strStore
                  strEcho = strEcho & " :: Is Enabled - " & strEnabled & " : SMTP Address: " & strMail
                  WScript.Echo strEcho
            End If
           
            If booWriteToFile = True Then
                  strLine = strDisplayName & VbTab & strUseLimits & VbTab & strWarnLimit &_
                              VbTab & strQuotaLimit & VbTab & strSize & VbTab & strServer &_
                              VbTab & strStore & VbTab & strEnabled & VbTab & strMail
                  objFile.WriteLine strLine
            End If
      Next
      If booWriteToFile = True Then
            Set objFile = Nothing
      End If
     
      If booWriteSummary = True Then
            Set objFile = objFileSystem.OpenTextFile(strSummaryFile, 2, True, 0)
            For i = 65 to 90
                  intTotal = 0
                  For Each strMailboxGUID in objResults
                        If Left(objResults(strMailboxGUID)(0), 1) = Chr(i) Then
                              If IsNumeric(objResults(strMailboxGUID)(4)) Then
                                    intTotal = intTotal + CDbl(objResults(strMailboxGUID)(4))
                              End If
                        End If
                  Next
                  objFile.WriteLine Chr(i) & VbTab & intTotal
            Next
      End If
     
      Set objFileSystem = Nothing
End Sub

'
' Main Code
'

' Global Variables

Dim objResults
Dim strServerName, strAdminGroup, strDomainName, strFileName, strSuffixes, strSummaryFile
Dim arrServerNames, arrForestDNs, arrForestDomains
Dim booServerName, booAdminGroup, booOrganisation, booResetSuffixes, booWriteToFile, booWriteSummary

SortArgv

Set objResults = CreateObject("Scripting.Dictionary")

GetADData

If booResetSuffixes = True And booOrganisation = True Then
      arrForestDNs = GetForestContexts
      arrForestDomains = ConvertToDNS(arrForestDNs)
      strSuffixes = SetSuffixes(arrForestDomains)
End If

If booServerName = True Then
      GetMailboxes(strServerName)
ElseIf booAdminGroup = True Then
      arrServerNames = GetExchangeServers(strAdminGroup)
      For Each strServerName in arrServerNames
            GetMailboxes(strServerName)
      Next
ElseIf booOrganisation = True Then
      arrServerNames = GetExchangeServers("")
      For Each strServerName in arrServerNames
            GetMailboxes(strServerName)
      Next
End If

If booResetSuffixes = True And booOrganisation = True Then
      ResetSuffixes strSuffixes
End If

CleanResults
WriteResults

Set objResults = Nothing
0
 
Chris DentPowerShell DeveloperCommented:

Hi Parker,

This one is VbScript, it'll need saving as .vbs. Then you'll need to fill in the Exchange Server Name at the top.

It'll create a Tab Delimited Text File containing the full Store Name (including it's path in AD which may be too much for you, let me know if you want less) and other details requested above.




Const EXCHANGE_SERVER_NAME = "SomeExchangeServer"
Const ADS_SCOPE_SUBTREE = 2

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

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT sAMAccountName, msExchHomeServerName, homeMDB, " &_
      "department FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") &_
      "' WHERE objectClass='user' AND objectCategory='person'"
Set objRootDSE = Nothing

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.OpenTextFile("Users.txt", 2, True, 0)

While Not objRecordSet.EOF
      strServer = "" : strServer = objRecordSet.Fields("msExchHomeServerName")

      If InStr(1, strServer, EXCHANGE_SERVER_NAME, VbTextCompare) > 0 Then
            strUsername = "" : strStore = "" : strDepartment = ""
            strUsername = objRecordSet.Fields("sAMAccountName")
            strStore = objRecordSet.Fields("homeMDB")
            strDepartment = objRecordSet.Fields("department")

            objFile.WriteLine strUsername & VbTab & strStore & VbTab &_
                  strDepartment
      End If

      objRecordSet.MoveNext
WEnd

Set objFile = Nothing
Set objFileSystem = Nothing
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
0
 
Erdrick33Author Commented:
Chris, I appreciate the quick response, script works like a charm.  What's some good material to look at to get a good intro at LDAP scripting in VBS?
0
 
Chris DentPowerShell DeveloperCommented:

The the MS Scripting Primers here make for a really good start:

http://www.microsoft.com/technet/scriptcenter/guide/sas_ads_overview.mspx?mfr=true

MS also do a collection of articles called "Hey, Scripting Guy":

http://www.microsoft.com/technet/scriptcenter/resources/qanda/hsgarch.mspx

Guy Thomas has a huge number of examples here, all well presented and explained:

http://www.computerperformance.co.uk/

More from Richard Mueller here:

http://www.rlmueller.net/

Then ActiveExperts have a great collection of little snippets, well worth digging into:

http://www.activexperts.com/activmonitor/windowsmanagement/

I have a number of scripts and functions here, but I really don't get around to doing much with my website so don't expect much from it:

http://www.highorbit.co.uk/scripting/CompleteScripts.asp
http://www.highorbit.co.uk/scripting/FunctionLib.asp

If you're considering using or learning scripting in full you would do well to consider PowerShell. It's more powerful than VbScript and will be heavily used with newer technologies from MS (Exchange 2007, Windows 2008, etc).

http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx

Guy Thomas has a lot on PowerShell as well (computerperformance). You can find even more here on Brandon's site:

http://bsonposh.com/modules/wordpress/

Chris
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now