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?
3 Answers
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.
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!
OP, seriously, use `-WhatIf`! It's super useful, especially when you're still learning and making widespread changes like this.
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!
Good point! That's an important tip to keep in mind.
Thank you! I'm still getting the hang of syntax, so this really helps!