Skip to content

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

Note

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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $admService.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