# Threshold size in GB
$thresholdSize = 20
# Get all user mailboxes
$mailboxes = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited
# Check each mailbox for size and archiving status
$mailboxes | ForEach-Object {
$mailbox = $_
$stats = Get-MailboxStatistics -Identity $mailbox.UserPrincipalName
$archiveEnabled = $mailbox.ArchiveStatus -eq "None"
# Extract mailbox size as a string (e.g., "20 GB")
$sizeString = $stats.TotalItemSize.ToString()
# Parse the numeric part of the size (e.g., "20" from "20 GB")
if ($sizeString -match "([\d\.]+) GB") {
$mailboxSizeGB = [double]$matches[1]
# Check if the mailbox exceeds the threshold and archiving is disabled
if ($mailboxSizeGB -gt $thresholdSize -and $archiveEnabled) {
[PSCustomObject]@{
DisplayName = $mailbox.DisplayName
UserPrincipalName = $mailbox.UserPrincipalName
MailboxSizeGB = $mailboxSizeGB
ArchiveEnabled = $mailbox.ArchiveStatus
}
}
}
} | Format-Table -AutoSize