|
Based on an MSDN Article, this script is designed to export mailbox sizes for a particular ou when the mailboxes for the users in the ou are spread out across multiple exchange servers. It only works with 2003 exchange servers, and uses an array for an internal cache to reduce exchange server requests.
It exports mailbox sizes by Organizational Unit using an array to scan multiple servers. It matches on name, which there could be multiple matches. I should go back and look at the WMI for Exchange 2003 and see if there is something else to use for a match, but now Exchange 2007 is out and this can be done much easier in powershell.
Script Code:
'This script only works with Exchange 2003 servers
Option Explicit
'i is our array counter for the exportarray, which is used as a cache array
Dim i
i=0
Dim ExportArray()
ReDim Exportarray(0)
On Error Resume Next
Function IsolateServerName(homeserver)
DIm AR
AR = Split(homeserver,"/cn=")
IsolateServerName = AR(3)
End Function
Sub StoreServer(Server)
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_Mailbox"
Dim strWinMgmts ' Connection string for WMI
Dim objWMIExchange ' Exchange Namespace WMI object
Dim listExchange_Mailboxes ' Exchange_Mailbox collection
Dim objExchange_Mailbox ' A single Exchange_Mailbox WMI object
' Create the object string, indicating WMI (winmgmts), using the
' current user credentials (impersonationLevel=impersonate),
' on the computer specified in the constant cComputerName, and
' using the CIM namespace for the Exchange provider.
strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//" & _
server & "/" & cWMINameSpace
Set objWMIExchange = GetObject (strWinMgmts)
' Verify we were able to correctly connect to
' the WMI namesspace on the server
If Err.Number <> 0 Then
MailBoxSize = "ERROR: Unable to connect to the " & _
"WMI namespace for user " & UserName & "."
Else
' The Resources that currently exist appear as a list of
' Exchange_Mailbox instances in the Exchange namespace.
Set listExchange_Mailboxes = objWMIExchange.InstancesOf (cWMIInstance)
' Were any Exchange_Mailbox Instances returned?
If (listExchange_Mailboxes.count <= 0) Then
Set objWMIExchange = Nothing
MailBoxSize = "WARNING: No Exchange_Mailbox instances" & _
" were returned for user " & UserName & "."
Else
' Iterate through the list of Exchange_Mailbox objects.
For Each objExchange_Mailbox in listExchange_Mailboxes
' Store in our cache file
Redim preserve ExportArray(i)
ExportArray(i) = Server & vbtab & _
objExchange_Mailbox.MailboxDisplayName & vbtab & _
FormatNumber (objExchange_Mailbox.Size, 0) & vbtab & _
FormatNumber (objExchange_Mailbox.TotalItems, 0)
' This was used for debugging
' TXT_MBW.WriteLine Server & vbtab & _
' objExchange_Mailbox.MailboxDisplayName & vbtab & _
' FormatNumber (objExchange_Mailbox.Size, 0) & vbtab & _
' FormatNumber (objExchange_Mailbox.TotalItems, 0)
i = i + 1
Next
End If
End If
Set objWMIExchange = Nothing
End Sub
Sub ExportMailboxSize(User)
If User.msExchHomeMDB="" Then
Exit Sub
End If
Dim ServerName
ServerName = IsolateServerName(user.msExchHomeServerName)
Dim LineFound
LineFound = Join(Filter(ExportArray,ServerName & _
vbTab & user.displayName & vbTab))
If Len(LineFound) = 0 Then
Dim Server
Server = Join(Filter(ExportArray,ServerName))
If Len(Server) = 0 Then
StoreServer(IsolateServerName(user.msExchHomeServerName))
LineFound = Join(Filter(ExportArray,ServerName & _
vbTab & user.displayName & vbTab))
Else
LineFound = ServerName & vbTab & user.displayname & _
vbTab & "ERROR" & vbTab & "Not Found"
End if
End if
TXT_MB.WriteLine LineFound
End Sub
Sub OULoop (OU)
Dim User
Dim subou
OU.Filter = Array("User")
For Each User in OU
ExportMailboxSize User
Next
OU.Filter = Array("OrganizationalUnit")
For Each subou in OU
OULoop subou
Next
End Sub
Dim FS
Set FS = CreateObject("Scripting.FileSystemObject")
Dim TXT_MB
Set TXT_MB = FS.OpenTextFile("Mailbox Sizes.txt", 2, True)
'This was used for debugging...
'Dim TXT_MBW
'Set TXT_MBW = FS.OpenTextFile("Mailbox Server Response.txt", 2, True)
TXT_MB.WriteLine "SERVER"&vbtab&"USER"&vbtab&"SIZE"&vbtab&"ITEMS"
Dim Root
Dim ROOTOU
Rootou = InputBox("Please modify the ldap path:", _
"Path to Export", _
"LDAP://EXMST/ou=USERS,ou=TUN,ou=Hosting,dc=exmst,dc=local")
Set Root = GetObject(ROOTOU)
OULoop Root
TXT_MB.Close
TXT_MBW.Close
Wscript.Echo "Complete"
|
Tonyroze makes this comment
Thursday, 14 January 2010
Anyway that it can skip the object and continue processing ?
Carlton makes this comment
Saturday, 23 January 2010
If User.msExchHomeMDB="" Then
Exit Sub
End If
That should keep it from getting caught up