Entra / Microsoft 365 · Exchange Online
Report auto expanding archives
Find mailboxes with auto-expanding archives and report proximity to the 1.5 TB limit, daily growth rate, and projected fill date.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-ExchangeOnline -ShowBanner:$false
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
$Modules = Get-ModuleIf ("ExchangeOnlineManagement" -notin $Modules.Name) {Write-Host "Please connect to Exchange Online Management before continuing...";break}If (((Get-OrganizationConfig).AutoExpandingArchiveEnabled) -ne $True) {Write-Host "Expanding archives are not enabled in this tenant" ; break}# Find set of archive-enabled mailboxes[array]$Mbx = Get-ExoMailbox -RecipientTypeDetails SharedMailbox, UserMailbox -Filter {ArchiveStatus -ne $Null} -ResultSize Unlimited -Properties ArchiveQuota, ArchiveStatus, AutoExpandingArchiveEnabled, RecipientTypeDetails, ArchiveName, WhenCreatedIf ($Mbx -eq 0) { Write-Host "No archive-enabled mailboxes found" ; break }# Number of bytes in 1.5 TB and 90% of that figure to generate warning[long]$TBBytes = "1649267441664"[long]$TBBytesWarning = $TBBytes * 0.9$Now = Get-Date# Reduce to the set of mailboxes with expanding archives[array]$ExMbx = $Mbx | Where-Object {$_.AutoExpandingArchiveEnabled -eq $True}If ($ExMbx -eq 0) { Write-Host "No mailboxes with expandable archives found" ; break }# Process each mailbox and identify how many days they can expand before hitting the limit$Report = [System.Collections.Generic.List[Object]]::new()ForEach ($M in $ExMbx) {$Status = $NullWrite-Host "Processing mailbox" $M.DisplayName[int]$DaysSinceCreation = ((New-TimeSpan -Start ($M.WhenCreated) -End ($Now)).Days)$Stats = Get-ExoMailboxStatistics -Archive -Identity $M.UserPrincipalName[string]$ArchiveSize = $Stats.TotalItemSize.Value[string]$DeletedArchiveItems = $Stats.TotalDeletedItemSize.Value[long]$BytesInArchive = $Stats.TotalItemSize.Value.ToBytes()[long]$BytesInRecoverableItems = $Stats.TotalDeletedItemSize.Value.ToBytes()[long]$TotalBytesInArchive = $BytesInArchive + $BytesInRecoverableItems# Check if archive size is within 10% of the 1.5 TB limit - the size that counts is the combination of Recoverable Items and normal foldersIf ($TotalBytesInArchive -ge $TBBytesWarning){ Write-Host ("Archive size {0} for {1} is within 10% of 1.5 TB limit" -f $ArchiveSize, $M.DisplayName )$Status = "Archive within 10% of 1.5 TB limit" }[long]$BytesPerDay = $TotalBytesInArchive/$DaysSinceCreation[long]$NumberDaysLeft = (($TBBytes - $TotalBytesInArchive)/$BytesPerDay)$BytesPerDayMB = $BytesPerDay/1MB$GrowthRateDay = [math]::Round($BytesPerDayMB,4)$TotalArchiveSizeGB = [math]::Round(($TotalBytesInArchive/1GB),2)$ReportLine = [PSCustomObject][Ordered]@{Mailbox = $M.DisplayNameUPN = $M.UserPrincipalNameCreated = $M.WhenCreatedDays = $DaysSinceCreationType = $M.RecipientTypeDetails"Archive Quota" = $M.ArchiveQuota.Split("(")[0]"Archive Status" = $M.ArchiveStatus"Archive Size" = $ArchiveSize.Split("(")[0]"Archive Items" = $Stats.ItemCount"Deleted Archive Items Size" = $DeletedArchiveItems.Split("(")[0]"Deleted Items" = $Stats.DeletedItemCount"Total Archive Size (GB)" = $TotalArchiveSizeGB"Daily Growth Rate (MB)" = $GrowthRateDay"Days Left to Limit" = $NumberDaysLeftStatus = $Status}$Report.Add($ReportLine)} #End ForEachWrite-Host ("{0} mailboxes processed" -f $Mbx.count)$Report | Select Mailbox, Type, "Archive Size", "Deleted Archive Items Size", "Total Archive Size (GB)", "Daily Growth Rate (MB)", "Days Left to Limit" | Out-GridView$Report | Export-CSV -NoTypeInformation c:\temp\ArchiveMailboxes.csv
Attribution
Author
Office365itpros