KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Report mailbox size for user group

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Library
View previous topic :: View next topic  
Author Message
jrweiss



Joined: 01 Mar 2003
Posts: 39

PostPosted: Sat Mar 08, 2003 1:32 am    Post subject: Reply with quote

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

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Marcus



Joined: 18 Nov 2002
Posts: 367

PostPosted: Mon Mar 10, 2003 4:01 am    Post subject: Reply with quote

>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....
Back to top
View user's profile Send private message
jrweiss



Joined: 01 Mar 2003
Posts: 39

PostPosted: Mon Mar 10, 2003 4:15 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Marcus



Joined: 18 Nov 2002
Posts: 367

PostPosted: Mon Mar 10, 2003 9:04 am    Post subject: Reply with quote

>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.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12792
Location: USA

PostPosted: Mon Mar 10, 2003 1:22 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
KS-Soft



Joined: 03 Apr 2002
Posts: 12792
Location: USA

PostPosted: Mon Mar 10, 2003 1:23 pm    Post subject: Reply with quote

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

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
jrweiss



Joined: 01 Mar 2003
Posts: 39

PostPosted: Mon Mar 10, 2003 11:44 pm    Post subject: Reply with quote

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.

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Marcus



Joined: 18 Nov 2002
Posts: 367

PostPosted: Tue Mar 11, 2003 3:20 am    Post subject: Reply with quote

>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.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12792
Location: USA

PostPosted: Tue Mar 11, 2003 8:21 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
jrweiss



Joined: 01 Mar 2003
Posts: 39

PostPosted: Tue Mar 11, 2003 11:49 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Marcus



Joined: 18 Nov 2002
Posts: 367

PostPosted: Wed Mar 12, 2003 3:47 am    Post subject: Reply with quote

>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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index