Question

I need to export Exchange details e.g. user name, last logon etc. to a excel worksheet. How can I do this please.

Asked by: odonab

I need to export the Microsoft Exchange 2003 details, e.g. username, last logon etc. to an excel worksheet.  Is this possible and if so how do I do it.  thanks.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-08-25 at 03:53:41ID23674860
Tags

Microsoft

,

Exchange

,

2003

Topic

Active Directory

Participating Experts
2
Points
125
Comments
4

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Logon script %username%
    I need a logon script to check whether a user file exist or not, if exist, the script will map a drive to user home dir. Logon.bat if exist \\servername\data\%username%.dat NET USE Z: /home so when the user logon with win98 client, and the file exist, it should map the driv...
  2. excel vba: export worksheet to text file
    how do i export an excel worksheet to a text file?
  3. Exporting Multiple Worksheets to Excel
    I am generating a report in Sql Server 2000 and would like to export various queries to an Excel file which needs to contain multiple worksheets. Is there a way to do this from a stored procedure or DTS?
  4. export into excel, separate worksheets
    hi experts, can you force crystal to export the records in an excel file into separate worksheets? would really appreciate any ideas on this. thanks. ann

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: drothbartPosted on 2008-08-25 at 09:36:53ID: 22306893

You can use csvde to create a CSV file, which Excel can import. You will get the information from Active Directory.

Sample (exports user information from the users OU in the domain.com domain, to a file called file.csv)
csvde -f file.csv -d "ou=users,dc=domain,dc=com" -r objectclass=user

http://blogs.techrepublic.com.com/networking/?p=427 has some further information.

 

by: bsharathPosted on 2008-08-25 at 22:05:12ID: 22311735

Here is a script that get these and many more details to a file. You get all these details
Display Name      Use Limits Enabled      Warning Limit      Quota Limit      Size on Server      Server Name      Storage Group      User Account Enabled      SMTP Address

Run this way
cscript mailbox.vbs -s your exchange server name  -f mail.txt

This code is from    "Chris Dent"


Hope this helps....

' 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
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:

Select allOpen in new window

 

by: bsharathPosted on 2008-08-25 at 22:05:14ID: 22311736

Here is a script that get these and many more details to a file. You get all these details
Display Name      Use Limits Enabled      Warning Limit      Quota Limit      Size on Server      Server Name      Storage Group      User Account Enabled      SMTP Address

Run this way
cscript mailbox.vbs -s your exchange server name  -f mail.txt

This code is from    "Chris Dent"


Hope this helps....

' 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
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:

Select allOpen in new window

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...