Working with Mailbox Rules in Powershell
1. Get all forwarding rules in an organization:
foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.ForwardTo} | fl MailboxOwnerID,Name,ForwardTo >> C:AllForwardRules.txt }
2. To get inbox rules for a mailbox:
Get-Inboxrule. You can also do get-inboxrule | Fl to see details of the rule
3. Type Get-command *inboxrule* to see list of commands for inbox rules
4. To remove a rule, type get-inboxrule | remove-inboxrule
5. Create inbox rule called Junk for a set of users in a particular OU called Test. this will rule will move messages with subject ‘spam” to a folder called
Junk email
$mailboxes = Get-mailbox -organizationalUnit test
$mailboxes | % { }
$mailboxes | % { New-inboxrule -Name Junk -mailbox $_.alias -subjectcontainswords “[spam]” -movetofolder “$($_.alias):Junk Email” }