Mailbox Usage

This code sample retrieves the following parameters of an Exchange mailbox:

  • Mailbox size
  • Total items
  • Last logon date
  • Logged on by
  • Storage qoutas
  • Deleted item retention

In the below code sample, the $mailboxParams variable represents properties of an Exchange mailbox. To retrieve the properties, use the IAdmExchangeMailParametersOps::GetMailParameters method.

 How
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Get Exchange properties
$mailboxParams = $user.GetMailParameters()
# The $mailboxParams variable represents properties of an Exchange mailbox

# Mailbox size
Write-Host "Mailbox size:" $mailboxParams.UsageInfo.Size

# Total items
Write-Host "Total items:" $mailboxParams.UsageInfo.TotalItemCount

# Last logon date
Write-Host "Last logon date:" $mailboxParams.UsageInfo.LastLogonDate

# Logged on by
Write-Host "Logged on by:" $mailboxParams.UsageInfo.LastLogonUserName

# Storage quotas
$storageQuotas = $mailboxParams.StorageQuotas
if ($storageQuotas.UseDatabaseQuotaDefaults)
{
    Write-Host "Storage quotas: Use mailbox database defaults"
}
else
{
    Write-Host "Storage quotas:"    
    
    # Issue warning quota
    if ($storageQuotas.IssueWarningQuota -ne $null)
    {
        $issueWarningQuota = $storageQuotas.IssueWarningQuota.GetGBytes()
        $issueWarningQuota = [System.Math]::Round($issueWarningQuota, 4)
        Write-Host "`tIssue warning at (GB):" $issueWarningQuota
    }
    
    # Prohibit send quota
    if ($storageQuotas.ProhibitSendQuota -ne $null)
    {
        $prohibitSendQuota = $storageQuotas.ProhibitSendQuota.GetGBytes()
        $prohibitSendQuota = [System.Math]::Round($prohibitSendQuota, 4)
        Write-Host "`tProhibit send at (GB):" $prohibitSendQuota
    }

    # Prohibit send and receive quota
    if ($storageQuotas.ProhibitSendReceiveQuota -ne $null)
    {
        $prohibitSendReceiveQuota = $storageQuotas.ProhibitSendReceiveQuota.GetGBytes()
        $prohibitSendReceiveQuota = [System.Math]::Round($prohibitSendReceiveQuota, 4)
        Write-Host "`tProhibit send and receive at (GB):" $prohibitSendReceiveQuota
    }
}

# Deleted item retention
if ($storageQuotas.UseDatabaseRetentionDefaults)
{
    Write-Host "Deleted Item Retention: Use mailbox database defaults"
}
else
{
    Write-Host "Deleted Item Retention:"
    Write-Host "`tKeep deleted Items for " $storageQuotas.RetainDeletedItemsFor " days"
    Write-Host "`tDon't permannently delete items until the database is backed up:" `
      $storageQuotas.RetainDeletedItemsUntilBackup
}

See also