I had a recent request to adjust all send and receive size limits on all mailboxes in one of my customer organizations. They had different admins set different levels for different groups and the CIO wanted them all the same now to reduce requests. He wanted them set to the Maximum Size of 150MB so that nobody would complain. He also wanted a count of mailboxes that were not compliant with the 150MB setting.
So, I came up with the following script to run. Feel free to take it and adjust it to maybe do a different mailbox group as this one does ALL mailboxes. I did set the script to let you choose what size limit you want (up to the limit of 150MB). Again, this is for Exchange Online so have a look and enjoy!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | <# .SYNOPSIS Reset all mailbox Send and Send/Receive values to the value you state for the Variables. .NOTES Name: Set-MaxSendReceiveSizes-AllMBX.ps1 Author: Lance Lingerfelt Version: 1.0 Modify Date: 2023-09-01 You MUST define the following Variables: $MaxSendSize - Set it to the size you want with a Maximum of 150MB. (Usually in MB: i.e. 10MB) $MaxSendReceiveSize - Set it to the size you want with a Maximum of 150MB. (Usually in MB: i.e. 10MB) Sent messages: If the user sends a message larger than the specified size, the message will be returned to the user with a descriptive error message. Received messages: If the user receives a message larger than the specified size, the message will be returned to the sender with a descriptive error message. .EXAMPLE .\Set-MaxSendReceiveSizes-AllMBX.ps1 -MaxSendSize 35MG -MaxSendReceiveSize 35MB .EXTERNALHELP https://learn.microsoft.com/en-us/exchange/recipients/user-mailboxes/mailbox-message-size-limits?view=exchserver-2019 #> #Define Manditory Variables [CmdletBinding(SupportsShouldProcess = $true)] Param( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $MaxSendSize, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $MaxSendReceiveSize ) # ================================================ # DO NOT MODIFY BEGIN # ================================================ $ErrorActionPreference = 'SilentlyContinue' $Date = Get-Date -Format "MM/dd/yyyy" # Set Logging Configuration $Log = [PSCustomObject]@{ Path = "C:\Temp\Logs\Set-MaxSendReceiveSizes-AllMBX" Name = "$($Date).log" } # ================================================ # DO NOT MODIFY END # ================================================ # ================================================ # SCRIPT BEGIN # ================================================ # Create New Logger Instance if Enabled Write-Host "Installing and Connecting Logger Instance (PoSHLog)" if ($PSCmdlet.ShouldProcess("Create New Logger Instance", $Log.Path)) { # Import Logger Module try { if ( -not (Get-Module -Name PoShLog -ListAvailable) ) { Install-Module -Name PoShLog -Scope CurrentUser -Force } else { Import-Module -Name PoShLog -Force } } catch { Write-Host -Object "Unable to import logger module. Error: $($_.Exception.Message)" exit 1 } # Create New Logger Instance. Verbose logging level. Log to file and console. Start Logger. New-Logger | ` Set-MinimumLevel -Value Verbose | ` Add-SinkFile -Path "$($Log.Path)\$($Log.Name)" -OutputTemplate ` '{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}' -RollingInterval Day | ` Add-SinkConsole | ` Start-Logger # Log Start of Script Write-VerboseLog "Start of Script." } Write-VerboseLog "Installing and Connecting Exchange Online" if ($PSCmdlet.ShouldProcess("Create New Exchange Online Instance", $Log.Path)) { # Import ExchangeOnlineManagement Module try { if ( -not (Get-Module -Name ExchangeOnlineManagement -ListAvailable) ) { Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser -Force } else { Import-Module -Name ExchangeOnlineManagement -Force } } catch { Write-Host -Object "Unable to import ExchangeOnlineManagement module. Error: $($_.Exception.Message)" exit 1 } } # Connect to Exchange Online Connect-ExchangeOnline -ShowBanner:$false # Get all mailboxes Write-VerboseLog "Getting All Mailboxes" $mailboxes = Get-Mailbox -ResultSize Unlimited # Initialize the non-compliant mailbox counter Write-VerboseLog "Setting up Counter for Non-Compliant Mailboxes" $nonCompliantCount = 0 # Iterate through each mailbox Write-VerboseLog "Setting Send and SendReceive Sizes on all mailboxes that are not compliant to $($MaxSendSize) Send and $($MaxSendReceiveSize) Send\Receive Size" foreach ($mailbox in $mailboxes) { $mailboxIdentity = $mailbox.Identity $mailboxDisplayName = $mailbox.DisplayName # Check if MaxSendSize is not set to 150MB if ($mailbox.MaxSendSize -ne "150 MB (157,286,400 bytes)") { Set-Mailbox -Identity $mailboxIdentity -MaxSendSize $MaxSendSize Write-VerboseLog "MaxSendSize updated to $($MaxSendSize) for mailbox: $mailboxDisplayName" $nonCompliantCount++ } # Check if MaxReceiveSize is not set to 150MB if ($mailbox.MaxReceiveSize -ne "150 MB (157,286,400 bytes)") { Set-Mailbox -Identity $mailboxIdentity -MaxReceiveSize $MaxSendReceiveSize Write-VerboseLog "MaxReceiveSize updated to $($MaxSendReceiveSize) for mailbox: $mailboxDisplayName" $nonCompliantCount++ } } # Display the number of non-compliant mailboxes Write-VerboseLog "Total non-compliant mailboxes: $nonCompliantCount" # Disconnect from Exchange Online Write-VerboseLog "Disconnecting Exchange Online" Disconnect-ExchangeOnline -Confirm:$false Write-VerboseLog "End of Script! Exiting!" # ================================================ # SCRIPT END # ================================================ |
THANKS FOR VIEWING! SEND ME YOUR IDEAS!
I AM GETTING MY GITHUB REPOSITORY TOGETHER!
About Lance Lingerfelt
Lance Lingerfelt is an M365 Specialist and Evangelist with over 20 years of experience in the Information Technology field. Having worked in enterprise environments to small businesses, he is able to adapt and provide the best IT Training and Consultation possible. With a focus on AI, the M365 Stack, and Healthcare, he continues to give back to the community with training, public speaking events, and this blog.