Search code examples
powershellforeachoutlookwhere-clauserules

Get-InboxRule but only show the ones where ForwardTo or ForwardAsAttachmentTo aren't empty


I have to check all our users Inbox rules. I managed to get all the inbox rules written to a text file. But i only need the ones where they forward it to an other mail.

What i have so far:

$mails = get-content D:\test.txt


$test = ForEach ($mail in $mails){


  $m = Get-InboxRule -Mailbox $mail | measure
  $mail
  $m.Count

}

$test| Out-File -FilePath "D:\testresult.txt" -Append

In the Test.txt i have all the Mail-addresses:

[email protected] 
[email protected]
[email protected]
etc etc.

How can can i add the check "where Forwardto -ne $null"?


Solution

  • You should add it to your Get-InboxRule command so

    Get-InboxRule -Mailbox $mail | measure
    

    becomes

    Get-InboxRule -Mailbox $mail | Where-Object {$_.ForwardTo -ne $Null} | measure