Check Size and Status of Archive Mailbox using PowerShell

Archive mailbox (Online or In-Place Archive) in Office 365 provides users with additional mailbox storage space. Once the archive feature is enabled for a mailbox, the mailbox user can easily copy or move the required messages to the Online Archive folder group in Outlook Desktop and In-Place Archive in Outlook Online.

In this post, I am going to share a PowerShell script to get the size and status of Exchange Online Archive mailboxes. If you looking to find users’ primary mailbox storage size, refer to this post: Mailbox size report.

We can use the Get-Mailbox cmdlet to check whether the archive feature is enabled or not in a mailbox. Once we confirmed the archive status enabled, we can use Get-MailboxStatistics to get the archive mailbox size and other mailbox-related statistics data.

Before you start, install the Exchange Online PowerShell V2 module and run the below command to connect Exchange Online Powershell.

Connect-ExchangeOnline

Run the following command to check the archive status for a mailbox. The property ArchiveStatus indicates the status of the archive mailbox, the value “Active” means the mailbox has an active archive mailbox.

Get-Mailbox -Identity "[email protected]"  | Select ArchiveStatus, ArchiveDatabase

As per this post, there may be a chance ArchiveStatus is set to “None” for an active archive mailbox in Office 365, so we can also check the property is ArchiveDatabase, if this property has any value then the mailbox has an active archive mailbox.

Once you confirmed the archive status for the mailbox, run the following command to get the size and archived items count.

Get-MailboxStatistics -Identity "[email protected]" -Archive | Select DisplayName, TotalItemSize, ItemCount

The parameter -Archive is the key input to get the archive mailbox. If you have not provided this property, the command simply returns the user’s primary mailbox statistics.

Find all Office 365 users with Active Archive Mailbox

Run the below command to list all the Office 365 users with the archive mailbox.

Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox  | Select DisplayName, ArchiveStatus

Instead of listing only archive mailboxes, if you want to get all user mailboxes with their archive mailbox status, you can run the below command.

Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox  |
 Select DisplayName, @{Label="ArchiveStatus";Expression={ if ($_.ArchiveStatus -eq "Active" -OR $_.ArchiveDatabase -ne $null) { "Enabled" } else {  "Disabled" }}}

Export Size and Status of Archive Mailbox for all Microsoft 365 users

Use the following Powershell script to get the archive status of all user mailboxes. Finally, the script exports the archived mailbox details such as mailbox name, archive status, archive state, mailbox size, and more.

$Result=@() 
#Get all user mailboxes
$mailboxes = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox
$totalmbx = $mailboxes.Count
$i = 0 
$mailboxes | ForEach-Object {
$i++
$mbx = $_
$size = $null

Write-Progress -activity "Processing $mbx" -status "$i out of $totalmbx completed"

if ($mbx.ArchiveStatus -eq "Active"){
#Get archive mailbox statistics
$mbs = Get-MailboxStatistics $mbx.UserPrincipalName -Archive

if ($mbs.TotalItemSize -ne $null){
$size = [math]::Round(($mbs.TotalItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2)
}else{
$size = 0 }
}

$Result += New-Object -TypeName PSObject -Property $([ordered]@{ 
UserName = $mbx.DisplayName
UserPrincipalName = $mbx.UserPrincipalName
ArchiveStatus =$mbx.ArchiveStatus
ArchiveName =$mbx.ArchiveName
ArchiveState =$mbx.ArchiveState
ArchiveMailboxSizeInMB = $size
ArchiveWarningQuota=if ($mbx.ArchiveStatus -eq "Active") {$mbx.ArchiveWarningQuota} Else { $null} 
ArchiveQuota = if ($mbx.ArchiveStatus -eq "Active") {$mbx.ArchiveQuota} Else { $null} 
AutoExpandingArchiveEnabled=$mbx.AutoExpandingArchiveEnabled
})
}
$Result | Export-CSV "C:\Temp\Archive-Mailbox-Report.csv" -NoTypeInformation -Encoding UTF8

Once you successfully run the above script, the output will be available in the Powershell object $Result. You can just filter the $Result array with Where-Object to generate further reports from this object. For example, run the below command to get details for only archive-enabled mailboxes.

$Result | Where-Object { $_.ArchiveStatus -eq "Active" } | Select UserName, UserPrincipalName, ArchiveMailboxSizeInMB, ArchiveWarningQuota, ArchiveQuota

Advertisement