{"id":196176,"date":"2023-09-01T15:52:39","date_gmt":"2023-09-01T20:52:39","guid":{"rendered":"https:\/\/itblog.ldlnet.net\/?p=196176"},"modified":"2024-05-10T08:32:24","modified_gmt":"2024-05-10T13:32:24","slug":"set-maxsendreceivesizes-allmbx-ps1","status":"publish","type":"post","link":"https:\/\/itblog.ldlnet.net\/index.php\/2023\/09\/01\/set-maxsendreceivesizes-allmbx-ps1\/","title":{"rendered":"Set-MaxSendReceiveSizes-AllMBX.ps1"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>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!<\/p>\n\n\n<pre class=\"lang:PowerShell nums:True\" title=\"Set-MaxSendReceiveSizes-AllMBX.ps1\">\n<#\n\n.SYNOPSIS\n\nReset all mailbox Send and Send\/Receive values to the value you state for the Variables.\n \n\n.NOTES\n\n    Name: Set-MaxSendReceiveSizes-AllMBX.ps1\n\n    Author: Lance Lingerfelt\n\n    Version: 1.0\n\n    Modify Date: 2023-09-01\n\n    You MUST define the following Variables:\n        $MaxSendSize - Set it to the size you want with a Maximum of 150MB. (Usually in MB: i.e. 10MB) \n        $MaxSendReceiveSize - Set it to the size you want with a Maximum of 150MB. (Usually in MB: i.e. 10MB)\n\n    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.\n    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.\n\n.EXAMPLE\n\n    .\\Set-MaxSendReceiveSizes-AllMBX.ps1 -MaxSendSize 35MG -MaxSendReceiveSize 35MB\n\n.EXTERNALHELP\n\n    https:\/\/learn.microsoft.com\/en-us\/exchange\/recipients\/user-mailboxes\/mailbox-message-size-limits?view=exchserver-2019\n\n#>\n\n#Define Manditory Variables\n\n[CmdletBinding(SupportsShouldProcess = $true)]\n\nParam(\n\n    [Parameter(Mandatory = $true)]\n\n    [ValidateNotNullOrEmpty()]\n\n    [string] $MaxSendSize,\n\n    [Parameter(Mandatory = $true)]\n    \n    [ValidateNotNullOrEmpty()]\n\n    [string] $MaxSendReceiveSize  \n\n)\n\n# ================================================\n#               DO NOT MODIFY BEGIN\n# ================================================\n\n$ErrorActionPreference = 'SilentlyContinue'\n\n$Date = Get-Date -Format \"MM\/dd\/yyyy\"\n\n# Set Logging Configuration\n$Log = [PSCustomObject]@{\n    Path = \"C:\\Temp\\Logs\\Set-MaxSendReceiveSizes-AllMBX\"\n    Name = \"$($Date).log\"\n}\n\n# ================================================\n#                DO NOT MODIFY END\n# ================================================\n\n# ================================================\n#                   SCRIPT BEGIN\n# ================================================\n\n# Create New Logger Instance if Enabled\nWrite-Host \"Installing and Connecting Logger Instance (PoSHLog)\"\nif ($PSCmdlet.ShouldProcess(\"Create New Logger Instance\", $Log.Path)) {\n    # Import Logger Module\n    try {\n        if ( -not (Get-Module -Name PoShLog -ListAvailable) ) {\n            Install-Module -Name PoShLog -Scope CurrentUser -Force\n        }\n        else {\n            Import-Module -Name PoShLog -Force\n        }\n    }\n    catch {\n        Write-Host -Object \"Unable to import logger module. Error: $($_.Exception.Message)\"\n        exit 1\n    }\n\n    # Create New Logger Instance. Verbose logging level. Log to file and console. Start Logger.\n    New-Logger | `\n        Set-MinimumLevel -Value Verbose | `\n        Add-SinkFile -Path \"$($Log.Path)\\$($Log.Name)\" -OutputTemplate `\n        '{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}' -RollingInterval Day | `\n        Add-SinkConsole | `\n        Start-Logger\n\n    # Log Start of Script\n    Write-VerboseLog \"Start of Script.\"\n}\n\nWrite-VerboseLog \"Installing and Connecting Exchange Online\"\nif ($PSCmdlet.ShouldProcess(\"Create New Exchange Online Instance\", $Log.Path)) {\n    # Import ExchangeOnlineManagement Module\n    try {\n        if ( -not (Get-Module -Name ExchangeOnlineManagement -ListAvailable) ) {\n            Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser -Force\n        }\n        else {\n            Import-Module -Name ExchangeOnlineManagement -Force\n        }\n    }\n    catch {\n        Write-Host -Object \"Unable to import ExchangeOnlineManagement module. Error: $($_.Exception.Message)\"\n        exit 1\n    }\n\n}\n\n# Connect to Exchange Online\nConnect-ExchangeOnline -ShowBanner:$false\n\n# Get all mailboxes\nWrite-VerboseLog \"Getting All Mailboxes\"\n$mailboxes = Get-Mailbox -ResultSize Unlimited\n\n# Initialize the non-compliant mailbox counter\nWrite-VerboseLog \"Setting up Counter for Non-Compliant Mailboxes\"\n$nonCompliantCount = 0\n\n# Iterate through each mailbox\nWrite-VerboseLog \"Setting Send and SendReceive Sizes on all mailboxes that are not compliant to $($MaxSendSize) Send and $($MaxSendReceiveSize) Send\\Receive Size\"\nforeach ($mailbox in $mailboxes) {\n    $mailboxIdentity = $mailbox.Identity\n    $mailboxDisplayName = $mailbox.DisplayName\n\n    # Check if MaxSendSize is not set to 150MB\n    if ($mailbox.MaxSendSize -ne \"150 MB (157,286,400 bytes)\") {\n        Set-Mailbox -Identity $mailboxIdentity -MaxSendSize $MaxSendSize\n        Write-VerboseLog \"MaxSendSize updated to $($MaxSendSize) for mailbox: $mailboxDisplayName\"\n        $nonCompliantCount++\n    }\n\n    # Check if MaxReceiveSize is not set to 150MB\n    if ($mailbox.MaxReceiveSize -ne \"150 MB (157,286,400 bytes)\") {\n        Set-Mailbox -Identity $mailboxIdentity -MaxReceiveSize $MaxSendReceiveSize\n        Write-VerboseLog \"MaxReceiveSize updated to $($MaxSendReceiveSize) for mailbox: $mailboxDisplayName\"\n        $nonCompliantCount++\n    }\n}\n\n# Display the number of non-compliant mailboxes\nWrite-VerboseLog \"Total non-compliant mailboxes: $nonCompliantCount\"\n\n# Disconnect from Exchange Online\nWrite-VerboseLog \"Disconnecting Exchange Online\"\nDisconnect-ExchangeOnline -Confirm:$false\n\nWrite-VerboseLog \"End of Script! Exiting!\"\n# ================================================\n#                   SCRIPT END\n# ================================================\n\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\">THANKS FOR VIEWING! SEND ME YOUR IDEAS!<br>I AM GETTING MY GITHUB REPOSITORY TOGETHER!<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">About Lance Lingerfelt<\/h2>\n\n\n\n<div class=\"wp-block-media-text is-stacked-on-mobile\" style=\"grid-template-columns:22% auto\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"468\" height=\"412\" src=\"https:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2024\/03\/ProfLDL1.jpg\" alt=\"Lance Lingerfelt Profile Photo\" class=\"wp-image-196223 size-full\"\/><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"has-small-font-size\">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.<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I had a recent request to adjust all send and receive size limits on all mailboxes in one of my customer organizations.<\/p>\n<p class=\"link-more\"><a class=\"myButt \" href=\"https:\/\/itblog.ldlnet.net\/index.php\/2023\/09\/01\/set-maxsendreceivesizes-allmbx-ps1\/\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":147,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,2,265,194,3],"tags":[15,9,316,8,315,13],"class_list":["post-196176","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-exchange","category-general","category-microsoft365","category-office365","category-powershell","tag-cmdlet","tag-exchange","tag-exo","tag-powershell","tag-powershell-script","tag-script","odd"],"_links":{"self":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/196176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/comments?post=196176"}],"version-history":[{"count":4,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/196176\/revisions"}],"predecessor-version":[{"id":196294,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/196176\/revisions\/196294"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media\/147"}],"wp:attachment":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media?parent=196176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/categories?post=196176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/tags?post=196176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}