Powershell Command To Display All User Mailbox InboxRules

Trying to run a Powershell Command To Display All User Mailbox InboxRules by running;  

Get-Mailbox -ResultSize unlimited | Get-InboxRule -ErrorAction:SilentlyContinue | Select MailboxOwnerID, name, from, redirectto, ForwardTo | Export-Csv c:\output\InboxRules_Forwards.csv -NoTypeInformation

...exports no information at all.

How can I run this via powershell to export ALL mailbox rules,

fields required/desired:

Enabled,Name,Priority,From,SentTo,CopyToFolder,DeleteMessage,ForwardTo,MarkAsRead,MoveToFolder,RedirectTo,SendTextMessageNotificationTo,MailboxOwnerId
Christian HansAsked:
Who is Participating?
 
Vasil Michev (MVP)Commented:
You are not getting any results because you are not using the pipeline correctly. The Get-InboxRule cmdlet uses the -Mailbox parameter to designate the mailbox object, and the -Identity parameter to designate the actual rule. In your case, you are passing the Identity. It doesnt matter anyway, as the -Mailbox parameter does not accept pipeline input.

In other words, use this:

Get-Mailbox -ResultSize Unlimited | % { Get-InboxRule -Mailbox $_.PrimarySmtpAddress }

Open in new window


not this

Get-Mailbox -ResultSize unlimited | Get-InboxRule -ErrorAction:SilentlyContinue 

Open in new window

0
 
Todd NelsonSystems EngineerCommented:
If it "exports no information at all" then there are probably no inbox rules set.

Also, if there are on premises and EXO mailboxes, you will need get info from EMS and also connected to EXO via PowerShell.

This command should work for both environments.  Just change the output location if running on the same machine.

Get-Mailbox -ResultSize Unlimited | Get-InboxRule -ErrorAction:SilentlyContinue | Select Enabled,Name,Priority,From,SentTo,CopyToFolder,DeleteMessage,ForwardTo,MarkAsRead,MoveToFolder,RedirectTo,@{Expression={$_.SendTextMessageNotificationTo};Label="SendTextMessageNotificationTo"},MailboxOwnerId | Export-Csv C:\Output\InboxRules_Forwards.csv -NoTypeInformation

Open in new window

0
 
Christian HansAuthor Commented:
Thanks Todd, running your suggestion now.

I have confirmed that we do have mailboxes with rules, plenty of them... which is why its so strange that the results didn't pull anything back.

Get-InboxRule -Mailbox First.Last@contoso.com pulls back rules...
0
 
Christian HansAuthor Commented:
Results = blank (no output)
0
 
Todd NelsonSystems EngineerCommented:
Huh?  I got output.

What Vasil provides will not work on premises because you have to pass a name or alias--not an email address.

Get-Mailbox -ResultSize Unlimited | % { Get-InboxRule -Mailbox $_.PrimarySmtpAddress }

Open in new window



But the following does (for both on premises Exchange and EXO), just like the previous command I provided (in on premises Exchange)...

Get-Mailbox -ResultSize Unlimited | % { Get-InboxRule -Mailbox $_.Alias }

Open in new window


And so does this...

Get-Mailbox -ResultSize Unlimited | % { Get-InboxRule -Mailbox $_.Name }

Open in new window



The following will output to a CSV file...

Get-Mailbox -ResultSize Unlimited | % { Get-InboxRule -Mailbox $_.Alias | Select Enabled,Name,Priority,From,SentTo,CopyToFolder,DeleteMessage,ForwardTo,MarkAsRead,MoveToFolder,RedirectTo,@{Expression={$_.SendTextMessageNotificationTo};Label="SendTextMessageNotificationTo"},MailboxOwnerId } | Export-Csv C:\Output\InboxRules_Forwards.csv -NoTypeInformation

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.