Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Fantasillion/7f162121dc354bee2697a73033b1ad8e to your computer and use it in GitHub Desktop.
Save Fantasillion/7f162121dc354bee2697a73033b1ad8e to your computer and use it in GitHub Desktop.
Export Size and Status of Archive Mailbox for all Microsoft 365 users with gui view
$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 | Out-GridView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment