Help with PowerShell Script for Setting User Inbox Sizes

0
6
Asked By TechWiz234 On

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

Answered By SyntaxSavvy On

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!

Answered By CodeGuru91 On

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.

Answered By DeploymentExpert On

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.