Help with PowerShell Script for Setting User Inbox Sizes

August 2, 2025 3 answers
Asked by TechWiz234
I'm working on a PowerShell script to set a uniform send and receive size for all user inboxes. I have this code: `$Users = Get-Mailbox -RecipientTypeDetails UserMailbox` followed by `ForEach($User in $Users) Set-Mailbox -Identity $user -MaxSendSize 153600KB -MaxReceiveSize 153600KB`. However, I'm getting an error that says 'Missing statement body in foreach loop.' Can someone help me figure out what I'm missing?

Answers

DeploymentExpert
Donโ€™t forget to add `-ResultSize Unlimited` to your `Get-Mailbox` command. Otherwise, you might miss some mailboxes in larger setups, which could lead to inconsistencies when you run your script!

SyntaxSavvy: Good point! That's an important tip to keep in mind.

Reply to this answer
CodeGuru91
You can simplify your command to a single line! Try this: ``` Get-Mailbox -RecipientTypeDetails UserMailbox | Set-Mailbox -MaxSendSize 153600KB -MaxReceiveSize 153600KB ``` If you want to see what changes would be made first, add the `-WhatIf` switch: ``` Get-Mailbox -RecipientTypeDetails UserMailbox | Set-Mailbox -MaxSendSize 153600KB -MaxReceiveSize 153600KB -WhatIf ``` It's a great way to check before committing any changes!

HelpfulUser123: OP, seriously, use `-WhatIf`! It's super useful, especially when you're still learning and making widespread changes like this.

Reply to this answer
SyntaxSavvy
It looks like you're missing the curly braces for your `ForEach` loop. Here's a quick example: ``` $letterArray = 'a','b','c','d' foreach ($letter in $letterArray) { Write-Host $letter } ``` So, try wrapping your `Set-Mailbox` command in curly braces! Check out the official PowerShell documentation for more guidance on `foreach` loops.

TechWiz234: Thank you! I'm still getting the hang of syntax, so this really helps!

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions