Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display mailbox quota

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
GB
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
 
Hi,

I've done a search and I think what I should be able to do is use this code to create a separate table in my database with the LDAP addresses of all user objects in my domain.

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

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

objCommand.CommandText = _
"<LDAP://dc=bb01,dc=com>;(objectCategory=user)" & _
";distinguishedName,name;subtree"

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name")
Wscript.Echo "[" & _
objRecordSet.Fields("distinguishedName") & "]"
objRecordSet.MoveNext
Wend

objConnection.Close

I think I can then do a join with my mailbox table and then execute some code based on that to get the mailbox quota.

Watch this space!

Thanks

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top