DESCRIPTION
This script calculates user mailbox size for a given user.
SCRIPT
'*********************************************************************************
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
' IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
' PLEASE CONTACT QUEST PROFESSIONAL SERVICES.
'*********************************************************************************
'
' This code is published on the ActiveRoles Script Center:
' http://communities.quest.com/docs/DOC-9991
'
' This code may use functions from the ARS Script Policy Best Practices:
' http://communities.quest.com/docs/DOC-10016
'
function onInit($context)
{
$par1 = $Context.AddParameter('AttrName')
$par1.MultiValued = $False
$par1.Description = 'Please specify LDAP name of attribute to keep user mailbox size'
}
function onPostGet($Request)
{
trap {continue}
if ($Request.Class -ine 'user') {exit}
$attrName = [string]$Context.Parameter('AttrName')
if (!$Request.IsAttributeRequested($attrName)) {exit}
$mailboxSize = GetMailboxSize $Request.DN
$EventLog.ReportEvent(4,"MailBox size is $mailboxSize bytes")
$Request.Put($attrName,$mailboxSize.ToString())
}
function GetMailboxSize($Identity)
{
trap {continue}
[void](Add-PSSnapin -Name 'Microsoft.Exchange.*' -ErrorAction 'SilentlyContinue')
$statistics = Get-MailboxStatistics -Identity $Identity -ErrorAction 'SilentlyContinue'
if ($statistics)
{
$statistics.TotalItemSize.Value.ToBytes()
}
else
{
0
}
}