Link to home
Start Free TrialLog in
Avatar of Andor Oudt
Andor OudtFlag for Netherlands

asked on

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

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"

User generated image

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).
Avatar of Andor Oudt
Andor Oudt
Flag of Netherlands image

ASKER

A bit surprised that I haven't received any response yet.....perhaps upping the stakes will influence this positively?
Avatar of RobSampson
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

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
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.
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.
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.
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?
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

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
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
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

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 ;)
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!

Added the specifics, but the results are still displayed on screen.
So what was giving you the right result on screen before you added the
| Out-File -append $outputFile
part?
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

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

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Rob,

can you throws some light on this question.

Q_27465808.html
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?
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

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!
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.
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.