MC884017
61 lines
# Install the Exchange Online PowerShell module if not already installed
# Install-Module -Name ExchangeOnlineManagement -Force -AllowClobber
# Import the Exchange Online PowerShell module
Import-Module ExchangeOnlineManagement
# Connect to Exchange Online
$UserCredential = Get-Credential
Connect-ExchangeOnline -UserPrincipalName $UserCredential.UserName -ShowProgress $true
# Define the limits with corrected property names
$limits = @{
"ExtensionCustomAttribute1" = @{ MaxLength = 2048; MaxCount = 750 }
"ExtensionCustomAttribute2" = @{ MaxLength = 2048; MaxCount = 750 }
"ExtensionCustomAttribute3" = @{ MaxLength = 2048; MaxCount = 400 }
"ExtensionCustomAttribute4" = @{ MaxLength = 2048; MaxCount = 400 }
"ExtensionCustomAttribute5" = @{ MaxLength = 2048; MaxCount = 250 }
"EmailAddresses" = @{ MaxLength = 1123; MaxCount = 1200 }
}
# Get all mailboxes
$mailboxes = Get-Mailbox -ResultSize Unlimited
# Check each mailbox against the limits
foreach ($mailbox in $mailboxes) {
# Use Get-Mailbox to retrieve relevant properties like ProxyAddresses and ArchiveName
$user = Get-Mailbox $mailbox.UserPrincipalName
# Use Get-User or Get-ADUser for custom attributes like ExtensionCustomAttribute1
$userExtended = Get-User $mailbox.UserPrincipalName
foreach ($property in $limits.Keys) {
$maxLength = $limits[$property].MaxLength
$maxCount = $limits[$property].MaxCount
# Get the current value for the property
if ($property -eq "ProxyAddresses") {
$propertyValue = $user.ProxyAddresses
}
elseif ($property -like "ExtensionCustomAttribute*") {
$propertyValue = $userExtended | Select-Object -ExpandProperty $property -EA 0
} else {
$propertyValue = $user | Select-Object -ExpandProperty $property -EA 0
}
if ($propertyValue) {
$currentLength = ($propertyValue | Out-String).Length
$currentCount = $propertyValue.Count
# Check if the property exceeds the limits
if ($currentLength -gt $maxLength -or $currentCount -gt $maxCount) {
Write-Host "Mailbox $($user.UserPrincipalName) exceeds limits for `${property}:"
Write-Host " Current Length: $currentLength, Max Length: $maxLength"
Write-Host " Current Count: $currentCount, Max Count: $maxCount"
}
}
}
}
# Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$false