We help IT Professionals succeed at work.

How to get statistics on the number of users having a auto-forward rule configured

Andor Oudt
Andor Oudt asked
on
Reader,

I would like to know how many users have configured and are using an auto-forward rule. From what I have so far is that such messages are flagged with 'Source = MAILBOXRULE'

I am working with the command to test the output and see what step to take next. I have generated output, so a hit should be returned, but the output show no results;
"Get-TransportServer | Get-MessageTrackingLog -Start "12/05/2011 15:00:00" -Recipient "<specific SMTP address>" -Sender "<specific SMTP address>" |FL MAILBOXRULE"

Powershell Command Output

The desired result is to have a log-file showing all the users that have an auto-forward rule configured (name, source, sender are values I would like to have in the overview).
Comment
Watch Question

Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
A bit surprised that I haven't received any response yet.....perhaps upping the stakes will influence this positively?
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, I'm not too good with Powershell, and I don't use Exchange, but I think the user properties that would interest you are the altRecipient property, and / or the deliverAndRedirect property.

Maybe something like this would work.

Regards,

Rob.
$domain = "dc=nwtraders,dc=com"
$dse = [adsi]"LDAP://$domain"
$filter = '(&(objectCategory=person)(objectSid=*)(!samAccountType:1.2.840.113556.1.4.804:=3)(deliverAndRedirect=$true))'
$searcher = New-Object DirectoryServices.DirectorySearcher ($dse, $filter)
$searcher.findall() | 
ForEach-Object {
[adsi]$_.path
} |
Format-Table -AutoSize -Property name, altRecipient, deliverAndRedirect

Open in new window

Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
Thanks for this. I will be able to test this tomorrow and will let you know the outcome and results.
As described int he below article you could get a list all the inbox rules and then may a quick seacrh should be able to get the require information.

http://www.msexchange.org/articles_tutorials/exchange-server-2010/management-administration/managing-inbox-rules-exchange-server-2010.html
Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
Rob, thanks for participating, but I am unsure how to proceed; how to incorporate this in a Powershell script?

I feel that the second suggestion/solution will provide the desired results, using the methods incorporated within the Exchange management infrastructure and mboppe, I think this is (exactly) what I am looking for, as a solution to the question.

Thanks for both suggestions/possible solutions, I will let you know as soon what the results are.
Most Valuable Expert 2012
Top Expert 2014

Commented:
Sure, if mboppe's solution meets your needs, then don't worry about the script I posted.  It *is* a Powershell script, though, so you can just put it into a .PS1 file and run it with Powershell.  You will need to change the domain name though, and then see what output you get.

Rob.
Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
Be assured that I am going to 'try' both suggested solutions and, if equally useful, points will be distributed accordingly... thanks again

Currently think that I will have a 'test-run' in two hours.
Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
OK....

Thanks to the heads-up from RobSampson &  mboppe I have found a possible method to extract data from all mailboxes configured with a RedirectTo rule.

This is what I am using now, but the output (at least WARNING: information) is directly generated on screen and I need to include all output in a log file:
foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.RedirectTo} | fl MailboxOwnerID,RedirectTo | Export-Csv C:\Users\Public\Documents\Get-InboxRule_RedirectTo.csv }

Open in new window


Any thoughts on improving the script?
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, again, I'm not too good with Powershell, but your script looks fine.  To output warnings as well, hopefully something like this will work.

Regards,

Rob.
$outputFile = "C:\Users\Public\Documents\Get-InboxRule_RedirectTo.csv"
$erroractionpreference = "SilentlyContinue"
foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.RedirectTo} | fl MailboxOwnerID,RedirectTo | Export-Csv $outputFile }
Write-Output $Error[($Error.count-1)..0] | Out-File -append $outputFile

Open in new window

Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
Hi Rob, thanks again....that simply looks exactly what it needs to do.....and more important, what I want to achieve.

I am currently enjoying some Poweshell Off time, but will definitely put your suggestion to good use, first thing tomorrow, when I hit the desk!

Cheers, again!
Thanks No-rad
let us know if you need any more help
Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
Yes, I need some more help.

When running the code provided by Rob, output is generated in the file, but displays errors, and I cannot seem to figure out why. I have attached the (sanitized) output file.

When running the initial code, removing the export/save functionality, I get exactly what I need:
MailboxOwnerId : <DN>
RedirectTo     :  <SMTP address>
The thing is (and this is key), that the script only generates the output 'on screen'

I am definitely missing something obviously simple here, but I cannot seem to find what....

Thanks again for all the effort!

foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.RedirectTo} | FL MailboxOwnerID,RedirectTo }

Open in new window

RedirectTo.log
Most Valuable Expert 2012
Top Expert 2014

Commented:
I forgot to add
$error.clear()

to the top of my code.  I think that all the errors in that log, except the last one, are actually old errors from the error buffer from other scripts.  The last error states:
.\d:\deliverandredirect.ps1

cannot be found, which may be correct.

Try this and see what you get on screen.

Rob.
$error.clear()
$outputFile = "C:\Users\Public\Documents\Get-InboxRule_RedirectTo.csv"
$erroractionpreference = "SilentlyContinue"
foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.RedirectTo} | fl MailboxOwnerID,RedirectTo}
Write-Output $Error[($Error.count-1)..0]

Open in new window

Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
Hi Rob,  Thanks for your continued effort in trying to assist. Super!

I already made some progress *, the following script generates and saves the requested/desired output:
foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.RedirectTo} | FL MailboxOwnerID,RedirectTo | Out-File -Append -FilePath c:\users\public\documents\RedirectTo.csv }

Open in new window


But only the MailboxOwnerID and RedirectTo values are written in the file. What I would like to add is DisplayName (instead of MailboxOwnerID) and PrimarySmtpAddress, but these values are from Get-Mailbox cmd-let.

Is there a way to get this information and also put it in the file? And are there any possibilities to influence the way the CSV file is being populated with data (EG can I custom format the output)?

I am going to execute your suggestion, right after I've stopped typing here!

Thanks again....

* being fairly new at Powershell, you can say it's a small step for you, but a big leap for me ;)
Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
Rob,

Just ran your script and it provides the desired results.
I have added " | Out-File -append $outputFile", after Write-Ouput $.... and I am executing another run

This is looking good!

Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
Added the specifics, but the results are still displayed on screen.
Most Valuable Expert 2012
Top Expert 2014

Commented:
So what was giving you the right result on screen before you added the
| Out-File -append $outputFile
part?
Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
This:
 
$error.clear()
$outputFile = "C:\Users\Public\Documents\Get-InboxRule_RedirectTo.csv"
$erroractionpreference = "SilentlyContinue"
foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.RedirectTo} | fl MailboxOwnerID,RedirectTo}
Write-Output $Error[($Error.count-1)..0]

Open in new window

Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
And this one does the trick as well, maybe slightly better:

foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | Where {$_.RedirectTo -like "*SMTP:*"} | FL MailboxOwnerID,RedirectTo | Out-File -Append -FilePath c:\users\public\documents\RedirectTo.csv }

Open in new window

Most Valuable Expert 2012
Top Expert 2014
Commented:
The one liner won't output the warnings to the output file though.  See how this goes.

Regards,

Rob.
$error.clear()
$outputFile = "C:\Users\Public\Documents\Get-InboxRule_RedirectTo.csv"
if ((Test-Path("$outputFile")) -eq $true) {remove-item "$outputFile"}
$erroractionpreference = "SilentlyContinue"
foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | where {$_.RedirectTo -like "*SMTP:*"} | FL MailboxOwnerID,RedirectTo | Out-File -append $outputFile }
Write-Output $Error[($Error.count-1)..0] | Out-File -append $outputFile

Open in new window

Kamaraj SubramanianApplication Support Analyst

Commented:
Hi Rob,

can you throws some light on this question.

Q_27465808.html
Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
Rob, You are right.

I ran the script and the output is generated/saved, but it doesn't show the warning messages in the same output. Although this is a 'nice-to-have' it doesn't constrain further analysis.

Based on the output I realized I need to find a way to match the MailboxOwnerId to the SMTP address belonging to that specific mailboxOwnerId. The value PrimarySmtpAddress is not a value that belongs to the Get-InboxRule cmd-let, the value belongs to the Get-Mailbox cmd-let

Because I need to match the two, I have the feeling that the value from one has to be piped into the output of the other cmd-let, shown as a third (MailboxOwnerID,RedirectTo,PrimarySmtpAddress) result. Although I think this can be achieved, I cannot seem to get this to work, in a one script.

Any thoughts?
Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
What I need in the final script, is to combine the output of two scripts, generating one log-file that has all the values required (MailboxOwnerID,RedirectTo,PrimarySmtpAddress), using the set criteria (Where {$_.RedirectTo -like "*SMTP:*"})

RedirectTo:
foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-InboxRule -Mailbox $i.DistinguishedName | Where {$_.RedirectTo -like "*SMTP:*"} | FL MailboxOwnerID,RedirectTo }

Open in new window

UserMailbox:
foreach ($i in (Get-Mailbox -ResultSize unlimited)) { Get-Mailbox -RecipientType UserMailbox -Identity $i.SamAccountName -ResultSize unlimited | FL Name,DisplayName,PrimarySmtpAddress }

Open in new window

Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
OK, I understand... perhaps I was getting a bit ahead of myself, trying to complement and complete the initial request and added some new requirements along the way.

I was just hoping to understand the script process a bit better, with your help.

Anyway the initial request has been answered and addressed by Rob, I suppose (even though the error output is still to be answered, in my opinion).

Thank you all for you continued support in this!
Andor OudtHybrid Cloud Infrastructure Consultant

Author

Commented:
Even though the script generates the desired outcome, without the ability to log the errors, I suppose the one liner Powershell script is sufficient and as efficient.
Most Valuable Expert 2012
Top Expert 2014

Commented:
Sorry.  I'm not that good with Powershell.  If you need further assistance with it, try posting another question in the Powershell zone and see if some more experienced coders can help you out.

Rob.