'AllMailBoxes.vbs 'Alan Kaplan, 9-12-2005 '1-23-07 fixed authentication issues, specifed clusters Option Explicit Dim wshShell Set wshShell = WScript.CreateObject("WScript.Shell") Dim quote quote=Chr(34) Dim strWinMgmts ' Connection string for WMI Dim objWMIExchange ' Exchange Namespace WMI object Dim collEMailBoxes ' ExchangeLogons collection Dim oExMailbox ' A single ExchangeLogon WMI object Dim aExchangeServers Dim strList, message 'Make sure running Cscript. If (Not IsCScript()) Then 'If not CScript, re-run with cscript... wshShell.Run "CScript.exe " & quote & WScript.ScriptFullName & quote, 1, True WScript.Quit '...and stop running as WScript End If ' ======= EDIT Here for defaults ======== strList = "EXCHANGE1,EXCHANGE2,EXCHANGE3" ' ======= End Edits ================ strList = ucase(strList) message = "This script uses WMI to get Mailbox information. " & _ "The query needs the cluster name if clustered, otherwise the physical server" & VbCrLf & vbCrLf & _ "Check Mailboxes on what servers?" strList = InputBox(message,"Exchange Servers",strList) If strList = "" Then WScript.Quit 'setup Log Dim fso,logfile, Appendout logfile = wshShell.ExpandEnvironmentStrings("%userprofile%") & "\desktop\Mailboxes.xls" 'new 1-22-07 prompt for path for logfile logfile = InputBox ("Save to:","Log Path",logfile) If logfile = "" Then WScript.Quit Const ForAppend = 8 Set fso = CreateObject("Scripting.FileSystemObject") 'Delete old logfile If fso.FileExists(logfile) Then fso.DeleteFile logfile,True End If set AppendOut = fso.OpenTextFile(logfile, ForAppend, True) Appendout.writeline "NT Name Display Name Limit Info Box Size(MB) Total Items Orphaned Store name StorageGroupName Server" 'a lot of the WMI stuff was lifted from 'http://www.msexchange.org/articles/Scripting-Exchange-VBScript-ADSI-Part3.html aExchangeServers = Split(strList,",") Const cWMINameSpace = "root/MicrosoftExchangeV2" Dim strServer WScript.Echo "Beginning Query. This can take a long time...." For Each strServer In aExchangeServers QueryServer ucase(strServer) Next MsgBox "Done. Logfile is " & logfile Sub QueryServer(strExchServer) Dim strDisplayName On Error Resume Next 'removed packet privacy from connection string 1-22-07 strWinMgmts = "winmgmts:{ImpersonationLevel=Impersonate, AuthenticationLevel=PktPrivacy}!//" & strExchServer & "/" & cWMINameSpace Set objWMIExchange = GetObject(strWinMgmts) ' Verify we were able to correctly set the object. If Err.Number <> 0 Then MsgBox "ERROR: Unable to connect to WMI. " & err.description,vbCritical+ vbOKOnly,"Error contacting " & strExchServer Else ' I found this fast than instances used in oroginal script -- A WScript.Echo VbCrLf & vbTab & "Getting Mailbox info from " & strExchServer & "." Dim iBoxcount Set collEMailBoxes = objWMIExchange.ExecQuery("Select * from Exchange_Mailbox") ' ' Were any Exchange_Mailbox Instances returned? iBoxcount = collEMailBoxes.count If ( iBoxcount > 0) Then WScript.Echo VbCrLf & "Found " & iBoxcount & " mailboxes on " & strExchServer & VbCrLf WScript.Sleep 3 'time to read ' If yes, do the following: ' Iterate through the list of Exchange_Mailbox objects. For Each oExMailbox in collEMailBoxes strDisplayName = oExMailbox.MailboxDisplayName 'Filter out system account stuff If InStr(strDisplayName,"SystemMailbox{")= 0 And InStr(strDisplayName,"SMTP (")= 0 Then EchoandLog CNName(oExMailbox.LegacyDN) & vbTab & strDisplayName & vbTab & _ LimitStatus(oExMailbox.StorageLimitInfo) & vbTab & inMB(oExMailbox.Size) & vbTab & _ oExMailbox.TotalItems & vbTab & IsOrphaned(oExMailbox.DateDiscoveredAbsentInDS) & vbTab & _ oExMailbox.StoreName & vbTab & oExMailbox.StorageGroupName & vbTab & oExMailbox.ServerName End If Next Else ' If no Exchange_Mailboxes were returned, display that. MsgBox "No Mailbox information could be gotten from " & strExchServer,vbCritical + vbOKOnly,"Error" End If End If End Sub Function IsCScript() If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then IsCScript = True Else IsCScript = False End If End Function Function LimitStatus(LimitInfo) Select Case LimitInfo Case 1 LimitStatus = "Below Limit" Case 2 LimitStatus = "Issue Warning" Case 4 LimitStatus = "Prohibit Send" Case 8 LimitStatus = "No Checking" Case 16 LimitStatus = "Mailbox Disabled" Case Else LimitStatus = "Unknown" End Select End Function Function inMB(iKBSize) If IsNull(iKBSize) Or iKBSize = 0 Then inMB = 0 Else inMB = round(iKBSize/1024,2) End If End Function Function IsOrphaned(dTest) 'WScript.Echo dtest If IsNull(dTest) Then IsOrphaned = "False" Else IsOrphaned = "True" End If End Function Function CNName(cnString) Dim atemp atemp = Split(cnstring,"=") CNName = atemp(UBound(atemp)) End Function Sub EchoAndLog (message) 'Echo output and write to log Wscript.Echo message AppendOut.WriteLine message End Sub