Sure,
$i references a mailbox. That has the offending owner of the invalid rule.
Here is a rule I require all code I work with to follow, otherwise it gets
filed in G:)
Always use `Set-StrictMode -Version Latest`
For every cmdlet that exposes it, use the -ErrorLevel parameter and either
try/catch it or ignore it (for the rare cases that might make sense).
So in your case, wrap the body in a try catch and report the offender, for
example:
try
{
Get-InboxRule... -ErrorAction Stop
}
catch
{
Write-Host ('{0} has an error.' -f $_.Identity)
}
A note about pipelines, while writing programs with a pipeline is
programmatically gruesome, you can rationalize it in some cases with Powershell.
By invoking Get-Mailbox outside the pipeline the way you are, all the objects
are accumulated in memory, then fed to the body one at a time.
That doesn't scale in large environments, but if this runs already you are
obviously ok.
hth,
jlc
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Maglinger, Paul
> Sent: Wednesday, November 1, 2017 1:04 PM
> To: [email protected]
> Subject: [Exchange] Outlook rules errors
>
> I'm using the following Powershell script to search for users that are using
> rules to either forward or redirect email outside of the company:
> # foreach ($i in (Get-Mailbox -ResultSize unlimited)) {Get-InboxRule -
> Mailbox $i.DistinguishedName | where {$_.ForwardTo} | fl
> MailboxOwnerID,Name,ForwardTo >> C:\downloads\ForwardRules.txt }
>
> While it runs this script I get a lot of warnings of "The Inbox rule
> "Blahblahblah" contains errors. To resolve the error, please edit the rule or
> re-create it."
>
> Very informative. not. I have no idea which mailbox to look at. Is there a
> way to refine the script, or is there another script that can be run that
> will tell
> me who has rules that have problems?
>
> Everything that I've found online talks about going into Outlook. I haven't
> found anything using PowerShell.
>
> Thanks!
>
> Paul
>
>
>