Hi,
I am developing a script that looks up the sizes, message count, mailbox name of all mailboxes. The script then writes that information to a small table in a database and then executes a query on that table to return them all mailboxes over a certain limit and puts them in order - the results are then emailed to me.
So far so good but now I also want to display the mailbox quota for each user.
The code I have (which works) is as follows - I have altered the names of the OU's slightly but the structure is the same.
Set objMailbox = GetObject("LDAP://cn=Ed Mozley, ou=Active Users, ou=My Office, ou=My Company,dc=MyDomain,dc=com")
warnLimit = 0
prohibitSendLimit = 0
prohibitSendReceiveLimit = 0
warnLimit = objMailbox.Get ("mDBStorageQuota")
prohibitSendLimit = objMailbox.Get ("mDBOverQuotaLimit")
wscript.echo(warnlimit)
wscript.echo(prohibitsendlimit)
Set objMailbox = Nothing
The problem I've got is that the user account won't always necessarily be in the the Active Users OU - they might be in 'Disabled' if they have left the firm or in the future we might set up other OU's for each department - eg 'Accounts', 'IT' etc.
I am using WMI to interrogate Exchange and was wondering if there is a way of looking up the LDAP path based on the mailbox name? We are using Exchange 2003 with Active Directory.
My code for looking up the mailbox sizes is as follows:
Dim cComputerName
Const cWMINameSpace = "root/MicrosoftExchangeV2"
'The rest of the script will fetch mailbox sizes for our server. Mailbox sizes are in Kilobytes.
Const cWMIInstance = "Exchange_Mailbox"
cComputerName = "EXCHANGE" ' Modify this value to suit your server
Dim strWinMgmts ' Connection string for WMI
Dim objWMIExchange ' Exchange Namespace WMI object
Dim listExchange_Mailboxs ' ExchangeLogons collection
Dim objExchange_Mailbox ' A single ExchangeLogon 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}!//"& _
cComputerName&"/"&cWMINameSpace
Set objWMIExchange = GetObject(strWinMgmts)
' Verify we were able to correctly set the object.
If Err.Number <> 0 Then
WScript.Echo "ERROR: Unable to connect to the WMI namespace."
Else
'
' The Resources that currently exist appear as a list of
' Exchange_Mailbox instances in the Exchange namespace.
Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)
'
' Were any Exchange_Mailbox Instances returned?
If (listExchange_Mailboxs.count > 0) Then
' If yes, do the following:
' Iterate through the list of Exchange_Mailbox objects.
For Each objExchange_Mailbox in listExchange_Mailboxs
MailboxName=Replace(objExchange_Mailbox.MailboxDisplayName, "'", "''")
LastLogon=Replace(objExchange_Mailbox.LastLoggedOnUserAccount, "'", "''")
MailboxSize=objExchange_Mailbox.Size
MailboxLimit=objExchange_Mailbox.StorageLimitInfo
TotalMessages=objExchange_Mailbox.TotalItems
WScript.echo "Checking " & MailboxName & "..."
TBL.Open "INSERT INTO bwbnet_ExchangeMailboxes " &_
"(MailboxName, LastLogon, MailboxSize, TotalMessages, Warning, Limit, DateChecked, TimeChecked) " &_
"VALUES (" &_
"'" & MailboxName & "', " &_
"'" & LastLogon & "', " &_
"'" & MailboxSize & "', " &_
"'" & TotalMessages & "', " &_
"'" & Warning & "', " &_
"'" & Limit & "', " &_
"'" & Date() & "', " &_
"'" & Time() & "')", DB
'
Next
Else
' If no Exchange_Mailbox instances were returned,
' display that.
WScript.Echo "WARNING: No Exchange_Mailbox instances were returned."
End If
End If
I am developing a script that looks up the sizes, message count, mailbox name of all mailboxes. The script then writes that information to a small table in a database and then executes a query on that table to return them all mailboxes over a certain limit and puts them in order - the results are then emailed to me.
So far so good but now I also want to display the mailbox quota for each user.
The code I have (which works) is as follows - I have altered the names of the OU's slightly but the structure is the same.
Set objMailbox = GetObject("LDAP://cn=Ed Mozley, ou=Active Users, ou=My Office, ou=My Company,dc=MyDomain,dc=com")
warnLimit = 0
prohibitSendLimit = 0
prohibitSendReceiveLimit = 0
warnLimit = objMailbox.Get ("mDBStorageQuota")
prohibitSendLimit = objMailbox.Get ("mDBOverQuotaLimit")
wscript.echo(warnlimit)
wscript.echo(prohibitsendlimit)
Set objMailbox = Nothing
The problem I've got is that the user account won't always necessarily be in the the Active Users OU - they might be in 'Disabled' if they have left the firm or in the future we might set up other OU's for each department - eg 'Accounts', 'IT' etc.
I am using WMI to interrogate Exchange and was wondering if there is a way of looking up the LDAP path based on the mailbox name? We are using Exchange 2003 with Active Directory.
My code for looking up the mailbox sizes is as follows:
Dim cComputerName
Const cWMINameSpace = "root/MicrosoftExchangeV2"
'The rest of the script will fetch mailbox sizes for our server. Mailbox sizes are in Kilobytes.
Const cWMIInstance = "Exchange_Mailbox"
cComputerName = "EXCHANGE" ' Modify this value to suit your server
Dim strWinMgmts ' Connection string for WMI
Dim objWMIExchange ' Exchange Namespace WMI object
Dim listExchange_Mailboxs ' ExchangeLogons collection
Dim objExchange_Mailbox ' A single ExchangeLogon 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}!//"& _
cComputerName&"/"&cWMINameSpace
Set objWMIExchange = GetObject(strWinMgmts)
' Verify we were able to correctly set the object.
If Err.Number <> 0 Then
WScript.Echo "ERROR: Unable to connect to the WMI namespace."
Else
'
' The Resources that currently exist appear as a list of
' Exchange_Mailbox instances in the Exchange namespace.
Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)
'
' Were any Exchange_Mailbox Instances returned?
If (listExchange_Mailboxs.count > 0) Then
' If yes, do the following:
' Iterate through the list of Exchange_Mailbox objects.
For Each objExchange_Mailbox in listExchange_Mailboxs
MailboxName=Replace(objExchange_Mailbox.MailboxDisplayName, "'", "''")
LastLogon=Replace(objExchange_Mailbox.LastLoggedOnUserAccount, "'", "''")
MailboxSize=objExchange_Mailbox.Size
MailboxLimit=objExchange_Mailbox.StorageLimitInfo
TotalMessages=objExchange_Mailbox.TotalItems
WScript.echo "Checking " & MailboxName & "..."
TBL.Open "INSERT INTO bwbnet_ExchangeMailboxes " &_
"(MailboxName, LastLogon, MailboxSize, TotalMessages, Warning, Limit, DateChecked, TimeChecked) " &_
"VALUES (" &_
"'" & MailboxName & "', " &_
"'" & LastLogon & "', " &_
"'" & MailboxSize & "', " &_
"'" & TotalMessages & "', " &_
"'" & Warning & "', " &_
"'" & Limit & "', " &_
"'" & Date() & "', " &_
"'" & Time() & "')", DB
'
Next
Else
' If no Exchange_Mailbox instances were returned,
' display that.
WScript.Echo "WARNING: No Exchange_Mailbox instances were returned."
End If
End If