To view the rules associated with a mailbox use the Get-InboxRule
cmdlet. Very useful when you are troubleshooting a remote user who is not getting emails and you suspect the rules could have a hand in it.
The cmdlet requires the initials of the user whose mailbox you want to check via the -Mailbox
switch:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
PS> Get-InboxRule -Mailbox rakhesh Name Enabled Priority RuleIdentity ---- ------- -------- ------------ SCOM Alerts True 1 4228791152867803137 MAPIMailbox::HandleObjectM... True 2 4300848746905731073 Backup Exec Alert True 3 4372906340943659009 Operations Manager Service... True 4 4444963934981586945 Move messages sent from Te... True 5 4517021529019514881 x_ServicedeskLondon (to) True 6 4589079123057442817 Facebook True 7 4661136717095370753 IsisOnlineBilling@isistele... True 8 4733194311133298689 Move messages sent from Ch... False 9 4805251905171226625 MAILER-DAEMON@messagelabs.com True 10 4877309499209154561 display a Desktop Alert True 11 4949367093247082497 |
To view a particular rule you can pass its name to the cmdlet:
1 2 3 4 5 |
PS> Get-InboxRule -Mailbox rakhesh "Facebook" Name Enabled Priority RuleIdentity ---- ------- -------- ------------ Facebook True 7 4661136717095370753 |
The good thing about manipulating rules via PowerShell is that you can filter based on the rule properties. Pipe the output to get-member
to see the various properties:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
PS> Get-InboxRule -Mailbox rakhesh | gm ... MarkAsRead Property System.Boolean {get;set;} MarkImportance Property {get;set;} MessageTypeMatches Property {get;set;} MoveToFolder Property System.String {get;set;} MyNameInCcBox Property System.Boolean {get;set;} MyNameInToBox Property System.Boolean {get;set;} MyNameInToOrCcBox Property System.Boolean {get;set;} MyNameNotInToBox Property System.Boolean {get;set;} Name Property System.String {get;set;} Priority Property System.Int32 {get;set;} ReceivedAfterDate Property {get;set;} ReceivedBeforeDate Property {get;set;} RecipientAddressContainsWords Property Deserialized.Microsoft.Exchange.Data.MultiValuedProperty`1[[Sy RedirectTo Property {get;set;} ... |
Then you can do stuff like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
PS> # find all rules where I delete the message PS> Get-InboxRule -Mailbox rakhesh | ?{ $_.DeleteMessage } Name Enabled Priority RuleIdentity ---- ------- -------- ------------ MAPIMailbox::HandleObjectM... True 2 4300848746905731073 Backup Exec Alert True 3 4372906340943659009 MAILER-DAEMON@messagelabs.com True 10 4877309499209154561 PS> # find all rules where I am filing the message PS> Get-InboxRule -Mailbox rakhesh | ?{ $_.MoveToFolder } Name Enabled Priority RuleIdentity ---- ------- -------- ------------ SCOM Alerts True 1 4228791152867803137 Operations Manager Service... True 4 4444963934981586945 Move messages sent from Te... True 5 4517021529019514881 x_ServicedeskLondon (to) True 6 4589079123057442817 IsisOnlineBilling@isistele... True 8 4733194311133298689 PS> # find all rules matching a particular domain in the from: address PS> Get-InboxRule -Mailbox rakhesh | ?{ $_.From -match "facebook" } Name Enabled Priority RuleIdentity ---- ------- -------- ------------ Facebook True 7 4661136717095370753 |
To disable and enable rules you have the Disable-InboxRule
and Enable-InboxRule
cmdlets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
PS> Disable-InboxRule -Mailbox rakhesh "Facebook" Confirm Using Outlook Web App or Windows PowerShell to modify your rules will delete any rules that were previously turned off using Outlook. If you want to preserve the rules you turned off using Outlook, select "No" and use Outlook to edit your rules. Are you sure you want to proceed? [Y] Yes [A] Yes to All [N] No [L] No to All [?] Help (default is "Y"): y This Inbox rule isn't supported by this version of Exchange. + CategoryInfo : InvalidOperation: (Facebook:InboxRuleIdParameter) [Disable-InboxRule], InvalidOperationE xception + FullyQualifiedErrorId : 783DD273,Microsoft.Exchange.Management.RecipientTasks.DisableInboxRule PS> # the error is because this is a client only rule and so can't be manipulated from the server PS> # so let's try another rule PS> Disable-InboxRule -Mailbox rakhesh "SCOM Alerts" Confirm Using Outlook Web App or Windows PowerShell to modify your rules will delete any rules that were previously turned off using Outlook. If you want to preserve the rules you turned off using Outlook, select "No" and use Outlook to edit your rules. Are you sure you want to proceed? [Y] Yes [A] Yes to All [N] No [L] No to All [?] Help (default is "Y"): PS> # enabling the previously disabled rule PS> Enable-InboxRule -Mailbox rakhesh "SCOM Alerts" |
Notice how the cmdlet failed for a client only rule? You can find such rules by using the SupportedByTask
property:
1 2 3 4 5 6 |
PS> Get-InboxRule -Mailbox rakhesh | ?{ !$_.SupportedByTask } | ft -AutoSize Name Enabled Priority RuleIdentity ---- ------- -------- ------------ Facebook True 7 16514055682962489345 display a Desktop Alert True 10 16730228465076273153 |
Lastly, to mass enable or disable rules do thus (in the examples below I am selecting rules matching certain criteria, but that’s optional):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
PS> Get-InboxRule -Mailbox rakhesh | ?{ $_.MoveToFolder } Name Enabled Priority RuleIdentity ---- ------- -------- ------------ SCOM Alerts True 1 16081710118734921729 Operations Manager Service... True 4 16297882900848705537 Move messages sent from Te... True 5 16369940494886633473 x_ServicedeskLondon (to) True 6 16441998088924561409 IsisOnlineBilling@isistele... True 8 16586113277000417281 PS> Get-InboxRule -Mailbox rakhesh | ?{ $_.MoveToFolder } | Disable-InboxRule PS> Get-InboxRule -Mailbox rakhesh | ?{ $_.MoveToFolder } Name Enabled Priority RuleIdentity ---- ------- -------- ------------ SCOM Alerts False 1 16081710118734921729 Operations Manager Service... False 4 16297882900848705537 Move messages sent from Te... False 5 16369940494886633473 x_ServicedeskLondon (to) False 6 16441998088924561409 IsisOnlineBilling@isistele... False 8 16586113277000417281 PS> Get-InboxRule -Mailbox rakhesh | ?{ $_.MoveToFolder } | Enable-InboxRule PS> Get-InboxRule -Mailbox rakhesh | ?{ $_.MoveToFolder } Name Enabled Priority RuleIdentity ---- ------- -------- ------------ SCOM Alerts True 1 16081710118734921729 Operations Manager Service... True 4 16297882900848705537 Move messages sent from Te... True 5 16369940494886633473 x_ServicedeskLondon (to) True 6 16441998088924561409 IsisOnlineBilling@isistele... True 8 16586113277000417281 |
PowerShell can also be used to create and delete rules. Like thus:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
PS> New-InboxRule -Mailbox rakhesh -Name "Mails from Gmail" -FromAddressContainsWords "gmail" -MoveToFolder "rakhesh:Hold" -StopProcessingRules $true Name Enabled Priority RuleIdentity ---- ------- -------- ------------ Mails from Gmail True 1 16946401247190056961 PS> Remove-InboxRule -Mailbox rakhesh "Mails from Gmail" Confirm Are you sure you want to perform this action? Removing inbox rule "Mails from Gmail" from mailbox "domain.com/path/to/OU/Sasidharan, Rakhesh". [Y] Yes [A] Yes to All [N] No [L] No to All [?] Help (default is "Y"): Y Confirm Using Outlook Web App or Windows PowerShell to modify your rules will delete any rules that were previously turned off using Outlook. If you want to preserve the rules you turned off using Outlook, select "No" and use Outlook to edit your rules. Are you sure you want to proceed? [Y] Yes [A] Yes to All [N] No [L] No to All [?] Help (default is "Y"): Y |