I gotta jump in here: >> 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.
In my experience, exactly the opposite is true. For example, if you've got 50,000 mailboxes and you are trying to use a pipeline with them, my experience says that exactly zero percent of the time will that pipeline complete without an error. 100% of the time you'll get "steppable pipeline already in use" or a similar error indicating that there were buffer collisions. P.S. - Another way to handle the OP's issue is with redirecting the warning stream. https://blogs.technet.microsoft.com/heyscriptingguy/2014/03/30/understanding-streams-redirection-and-write-host-in-powershell/ -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Joseph L. Casale Sent: Wednesday, November 1, 2017 3:30 PM To: '[email protected]' Subject: [Exchange] RE: Outlook rules errors 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 > > >
