July 2017
Intermediate to advanced
648 pages
31h 9m
English
Now let's take a look at a practical example of how you might create inbox rules in bulk. The following code will create an inbox rule for every mailbox in the Sales OU:
$sales = Get-Mailbox -OrganizationalUnit contoso.com/sales
$sales | %{
New-InboxRule -Name Junk `
-Mailbox $_.alias `
-SubjectContainsWords "[Spam]" `
-MoveToFolder "$($_.alias):\Junk Email"
}
What we are doing here is using the -SubjectContainsWords parameter to check for a subject line that starts with [Spam]. If there is a match, we move the message to the Junk Email folder within that user's mailbox. As you can see, we are looping through each mailbox using the ForEach-Object cmdlet (using the % alias), and, within the loop, we specify the identity ...
Read now
Unlock full access