Script Error for Shared Mailbox Threshold Report

Copper Contributor

Hello All

 

Am getting the below error , while am trying to run the below script

 

i would like to get the report on exchange server 2019 to find the list of shared mailboxes whose shared mailbox near filled with specific Percentage

 

Could someone run the script and help me please

 

Say of example : if any shared mailbox reach 50 % of usage . it should get give in the report 

==================================================================

$ThresholdPercentage =  50 # Example: 90%

# Get all mailboxes and their quotas

$mailboxes = Get-Mailbox -ResultSize Unlimited

 

foreach ($mailbox in $mailboxes) {

    # Calculate the usage percentage

    if ($mailbox.ProhibitSendReceiveQuota -ne "unlimited") {

        $quota = [int]$mailbox.ProhibitSendReceiveQuota

        $usage = [int]$mailbox.TotalItemSize.Value.ToBytes() / $quota * 100

    }

    else {

        # If the quota is unlimited, consider it as 0% usage (since it's not limited)

        $usage = 0

    }

   

    # Check if usage exceeds the threshold

    if ($usage -ge $ThresholdPercentage) {

        # Output or process the mailbox as needed

        Write-Host "Mailbox $($mailbox.DisplayName) ($($mailbox.PrimarySmtpAddress)) is at $($usage)% of quota."

       

        # Optionally, you can output to a CSV file or perform other actions

        # Example: $mailbox | Select DisplayName, PrimarySmtpAddress, @{Name="UsagePercentage";Expression={$usage}} | Export-Csv -Path "MailboxUsageReport.csv" -Append -NoTypeInformation

    }

}

===========================================================

 

 

0 Replies