Jump to content
Sign in to follow this  
NeilA

Exchange Mailbox Size

Recommended Posts

NeilA

Does anyone have a script that will collect one or more users mailbox size from an Exchange server.

I can do this via a VBS script but can't get it to work using AutoIt.

Share this post


Link to post
Share on other sites
sandman

Could we see the VB code? That might help.


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites
NeilA

VBS Script is:

On Error Resume Next

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"

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

Dim objFileSystem, objOutputFile

Dim strOutputFile

' generate a filename base on the script name

strOutputFile = "mailboxsizes.txt"

Set objFileSystem = CreateObject("Scripting.fileSystemObject")

Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)

WScript.Echo "Running"

Mailsize("SERVER1")

Mailsize("SERVER2")

Mailsize("SERVER3")

Mailsize("SERVER4")

WScript.Echo "Finished"

objOutputFile.Close

Set objFileSystem = Nothing

Sub Mailsize(cComputerName)

' 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, Iterate through the list of Exchange_Mailbox objects.

For Each objExchange_Mailbox in listExchange_Mailboxs

'

' Display the value of the Size property.

objOutputFile.WriteLine objExchange_Mailbox.MailboxDisplayName & "|" & objExchange_Mailbox.Size & "|" & cComputerName

Next

Else

' If no Exchange_Mailbox instances were returned, display that fact.

WScript.Echo "WARNING: No Exchange_Mailbox instances were returned."

End If

End If

End Sub

Share this post


Link to post
Share on other sites
ptrex

@NeilA

Maybe this can be of any use

; This code lists the size of all mailboxes on the selected server.

; ------ SCRIPT CONFIGURATION ------
 $strComputerName = "<serverName>"  ; e.g. "batman"
   
; ------ END CONFIGURATION ---------
  $strE2K3WMIQuery = "winmgmts://" & $strComputerName & "/root/MicrosoftExchangeV2"
  
  ; Find each $mailbox on the target server and report their
  ; item counts and sizes
   $mboxList = ObjGet($strE2K3WMIQuery)
   $mbox = $mboxList.InstancesOf("Exchange_Mailbox")
  
  For $mailbox in $mbox
    $strOutput = ""
    $strOutput =  "Mailbox: " & $mailbox.MailboxDisplayName & @CRLF
    $strOutput = $strOutput &  "   " & $mailbox.Size & "KB in " & $mailbox.TotalItems & _
         " items" & @CRLF
    ConsoleWrite ($strOutput & @CRLF)
  Next

Regards

ptrex

Share this post


Link to post
Share on other sites
NeilA

ptrex

This works perfectly, thanks very much. I can stop banging my head against that wall now.

NeilA

Share this post


Link to post
Share on other sites
ptrex

@NeilA

Glad to see it works.

I have got +500 scritp lying around translated from Vbs to AU3.

All Scipts ready to use for a Business environment, like Active Directory, Server 2003, Exchange, Etc.

But I am not sure if I am willing to share them all for free. :)

Regards

ptrex

Edited by ptrex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×