Script repository
The script saves mailbox size to an Active Directory attribute. To execute the script, create a business rule, custom command or scheduled task configured for the required object type.
In the script, the $attributeName variable specifies the name of the attribute to save the mailbox size to.
$attributeName = "adm-CustomAttributeText1" # TODO: modify me
# Get Exchange properties.
$mailboxParams = $Context.TargetObject.GetMailParameters()
$sizeInBytes = $mailboxParams.UsageInfo.Size.TotalSize
if ($sizeInBytes -eq $NULL)
{
return
}
# Get mailbox size.
switch -Regex ([Math]::Truncate([Math]::Log($sizeInBytes, 1024))) {
'^1' { $sizeDisp = "{0:N2} KB" -f ($sizeInBytes / 1KB) }
'^2' { $sizeDisp = "{0:N2} MB" -f ($sizeInBytes / 1MB) }
'^3' { $sizeDisp = "{0:N2} GB" -f ($sizeInBytes / 1GB) }
'^4' { $sizeDisp = "{0:N2} TB" -f ($sizeInBytes / 1TB) }
Default { $sizeDisp = "$sizeInBytes Bytes" }
}
# Update attribute
$Context.TargetObject.Put($attributeName, $sizeDisp)
$Context.TargetObject.SetInfo()
Comments 0
You must be signed in to comment.