Report mailbox size for user group

If you have information, script, utility, or idea that can be useful for HostMonitor community, you welcome to share information in this forum.
Post Reply
jrweiss
Posts: 39
Joined: Sat Mar 01, 2003 6:00 pm
Contact:

Post by jrweiss »

The below script calculates the size of mailboxes for a given user group. It does run without problems from a command line with cscript/wscript but not within HM. Can somebody assist?

'-----------------------------------------------------------------------------
'File : E2k-MBspace.VBS
'Purpose : Determines the size of all mailboxes of a certain group
'Language: VBScript
'Version : 1.0
'Author : Logical Networks (PTY) Ltd. - JRW
'-----------------------------------------------------------------------------
Option Explicit

const statusAlive = "Host is alive:"
const statusDead = "No answer:"
const statusUnknown = "Unknown:"
const statusNotResolved = "Unknown host:"
const statusOk = "Ok:"
const statusBad = "Bad:"
const statusBadContents = "Bad contents:"
const adCmdStoredProc = &H0004
const adBoolean = 11
const UserGroup = "MyGroup" ' Group for which you want the mailbox size
const GroupOU = ",OU=OrgUnit1, OU=OrgUnit2, OU=OrgUnit3" ' OU path where to find the UserGroup
const Domain = ",DC=MyCompany,DC=com" ' Domain to contact
const MailServer = "MyMailServer"

' Comment out, for testing outside HM
' Dim sMsg
' sMsg = MsgBox(PerformTest()) '

Function PerformTest()
Dim sMailBoxSize, i, sMsg
Dim oGroup
Dim oUser
Dim oSession
Dim oInfoStores
Dim oInfoStore
Dim iStorageUsed
Dim iNumMessages
Dim sProfileInfo

On Error Resume Next

' Get all users of a certain group
Set oGroup = GetObject("LDAP://CN=" & UserGroup & GroupOU & Domain)
If (Err.Number <> 0) then
PerformTest = statusUnknown & Err.Description & " (1)"
Exit Function
End If

i = 0
For each oUser in oGroup.Members
ReDim Preserve arrUserList(i)
arrUserList(i) = oUser.userPrincipalName
If (Err.Number <> 0) then
PerformTest = statusUnknown & Err.Description & " (2)"
Exit Function
End If
i = i + 1
Next


' Get Mailbox Size for Each User
iStorageUsed = CLng(0) ' Size of Mailbox in in Bytes
iNumMessages = CLng(0) ' Number of message in Mailbox
For i=0 To Ubound(arrUserList)

Set oSession = CreateObject("MAPI.Session")
If (Err.Number <> 0) then
PerformTest = statusUnknown & Err.Description & " (3)"
Exit Function
End If

sProfileInfo = MailServer & vbLf & arrUserList(i)
oSession.Logon , , False, True, , True, sProfileInfo 'Logon
If (Err.Number <> 0) then
PerformTest = statusUnknown & Err.Description & " (4)"
Exit Function
End If

Set oInfoStores = oSession.InfoStores 'Grab the info stores
If (Err.Number <> 0) then
PerformTest = statusUnknown & Err.Description & " (5)"
Exit Function
End If

For Each oInfoStore In oInfoStores 'Loop through info stores to find user's mailbox
If InStr(1, oInfoStore.Name, "Mailbox - ", 1) <> 0 Then

iStorageUsed = iStorageUsed + CLng(oInfoStore.Fields(&HE080003)) '&HE080003 = PR MESSAGE SIZE
If (Err.Number <> 0) then
PerformTest = statusUnknown & Err.Description & " (6)"
Exit Function
End If

iNumMessages = iNumMessages + CLng(oInfoStore.Fields(&H36020003)) '&H33020003 = PR CONTENT COUNT
If (Err.Number <> 0) then
PerformTest = statusUnknown & Err.Description & " (7)"
Exit Function
End If

End If
Next 'For Each oInfoStore In oInfoStores

oSession.Logoff 'Log off

Next ' i=0 To Ubound(arrUserList)

oGroup = ""
oUser = ""
oSession = ""
oInfoStores = ""
oInfoStore = ""

performtest = statusOk & CStr(CLng(iStorageUsed / 1024 /1024)) & " Mb" 'Report back in Mbytes

End Function

User avatar
Marcus
Posts: 367
Joined: Mon Nov 18, 2002 6:00 pm

Post by Marcus »

>It does run without problems from a command line with cscript/wscript but not within HM

Do you use the same account when running the script from the command line? Since you ask information from the DC, it could be a permission problem....
jrweiss
Posts: 39
Joined: Sat Mar 01, 2003 6:00 pm
Contact:

Post by jrweiss »

Hi Marcus,
the LDAP access works without problems. It's the MAPI access which causes trouble. I tested the script with an Domain Admin account and it works. Then I logged on interactively with the account that I specify under HM-Options (run as service) and it also works.
But when I add a test executing the script it doesn't. Could it be that HM is not executing the script under the account provided in HM-Options?

Thanx and Regards, J.
User avatar
Marcus
Posts: 367
Joined: Mon Nov 18, 2002 6:00 pm

Post by Marcus »

>But when I add a test executing the script it doesn't

I assume the Hostmonitor application itselfs runs under the system account. Change it to the account needed for your mail server and it wil work.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Yes, HostMonitor starts under local system account. But to perform tests it uses account specified on Service page in the Options dialog.
My suggestions:
- check NT Event Log. If HostMonitor cannot use specified account (e.g. wrong password), there must be record like "Cannot logon as user ..."
- check does other account-specific tests (e.g. UNC, CPU Usage) work properly
- logon locally (using the same account), start HostMonitor as application, select test that executes the script, open Test Properties dialog and click "Test" button. You will see what error scripting engine returns.

Regards
Alex
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

BTW What version of HM do you use? If you have some problem, please, always include information about OS and HM.

Regards
Alex
jrweiss
Posts: 39
Joined: Sat Mar 01, 2003 6:00 pm
Contact:

Post by jrweiss »

Marcus:
Yes, Alex is right (see post after yours). It wouldn't help anyway to change the Service Account under W2k/NT because you can' access the console anymore.

Alex:
a) No messages in eventlog
b) CPU / perf. counter tests work well
c) When I test the script (Test button) I am getting Error -214024843 (Line 39)
d) HM Version: 3.64 and 3.68 (testing with both), OS Version: WinXP SP1

Thanx, J.

User avatar
Marcus
Posts: 367
Joined: Mon Nov 18, 2002 6:00 pm

Post by Marcus »

>But to perform tests it uses account specified on Service page in the Options dialog.

I can only say that the account on the service page and the startup account for Hostmonitor as a service are the same in my configuration and it always works, even across domains.

>It wouldn't help anyway to change the Service Account under W2k/NT because you can' access the console anymore.
You can't access the service directly, but stopping the service and starting the application gives you full control again.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

After investigation I can say that HostMonitor starts thread that correctly impersonates specified user. Problem is scripting engine starts another thread to process the script and this thread inherits application's permissions. We will try to find some workaround, but probably the only possible solution is to start service using another account (defined by standard Services utility).
Marcus was right

Regards
Alex
jrweiss
Posts: 39
Joined: Sat Mar 01, 2003 6:00 pm
Contact:

Post by jrweiss »

Hi Alex,

thanks very much. At least I know now that it is not the script. Will wait for you in anticipation for a work-around. Starting HM under a different account is unfortenuately not an option for us since we want to see the console at all times in our data centre.

Anyway, great support from you (and Marcus). Many thanks, J.
User avatar
Marcus
Posts: 367
Joined: Mon Nov 18, 2002 6:00 pm

Post by Marcus »

>Starting HM under a different account is unfortenuately not an option for us since we want to see the console at all times in our data centre

If security permits, you can login with the non-system account and run hostmonitor as application instead of service.

Or you can create a report on a web-server for status checking.
Post Reply