- Get link
- X
- Other Apps
This script will generate report in CSV for the rules currently setup to forward or redirect messages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#==================================================== | |
# Get-InboxRule-External-and-RedirectTo.ps1 | |
# Author: Sunil Chauhan | |
# Email:Sunilkms@gmail.com | |
# website:sunil-Chauhan.blogspot.com | |
# This scripts gets all the forwarding and redirectTo Rules and ` | |
# Create a Report in a presentable format. | |
#==================================================== | |
Write-host "Getting All User Mailboxes.." | |
$AllMailboxes = Get-Mailbox -resultSize Unlimited | |
$AllRules = @() | |
$c=0 | |
foreach ($mbx in $allMailboxes) | |
{ | |
$c++ | |
Write-host "$C : Getting Rules For User Mailbox:" $mbx.Alias | |
$mbxRules= Get-InboxRule -Mailbox $mbx.Alias | |
$AllRules+=$MbxRules | |
} | |
$Rules = $AllRules | ? {$_.Description -match "@" -and $_.ForwardTo -ne $null -or $_.RedirectTo -ne $null} | |
$RulesDATA=@() | |
foreach ($rule in $Rules) | |
{ | |
if ($rule.ForwardTo) | |
{ | |
if (($rule.ForwardTo).Count -gt 1) | |
{ | |
foreach ($entry in $rule.ForwardTo) | |
{ | |
if ($entry -match "@"){ | |
$RulesD= New-Object -TypeName PSObject | |
$RulesD| Add-Member -MemberType NoteProperty -Name Mailbox -Value $rule.MailboxOwnerID | |
$RulesD| Add-Member -MemberType NoteProperty -Name ForwardTo -Value $($entry | % {$($_.split("[")[0]).Replace('"',"")}) | |
#$RulesD| Add-Member -MemberType NoteProperty -Name ForwardTo -Value $entry | |
$RulesD| Add-Member -MemberType NoteProperty -Name RedirectTo -Value "n/a" | |
$RulesDATA+=$rulesD} | |
} | |
} | |
Else{ | |
if ($rule.ForwardTo -match "@"){ | |
$RulesD= New-Object -TypeName PSObject | |
$RulesD| Add-Member -MemberType NoteProperty -Name Mailbox -Value $rule.MailboxOwnerID | |
$RulesD| Add-Member -MemberType NoteProperty -Name ForwardTo -Value $($rule.ForwardTo | % {$($_.split("[")[0]).Replace('"',"")}) | |
$RulesD| Add-Member -MemberType NoteProperty -Name RedirectTo -Value "n/a" | |
$RulesDATA+=$rulesD} | |
} | |
} | |
if ($rule.RedirectTo) | |
{ | |
if (($rule.RedirectTo).Count -gt 1) | |
{ | |
foreach ($entry in $rule.RedirectTo) | |
{ | |
if ($entry -match "@") { | |
$RulesD= New-Object -TypeName PSObject | |
$RulesD| Add-Member -MemberType NoteProperty -Name Mailbox -Value $rule.MailboxOwnerID | |
$RulesD| Add-Member -MemberType NoteProperty -Name ForwardTo -Value n/a | |
$RulesD| Add-Member -MemberType NoteProperty -Name RedirectTo -Value $($entry | % {$($_.split("[")[0]).Replace('"',"")}) | |
$RulesDATA+=$rulesD} | |
} | |
} | |
Else{ | |
if ($rule.RedirectTo -match "@") { | |
$RulesD= New-Object -TypeName PSObject | |
$RulesD| Add-Member -MemberType NoteProperty -Name Mailbox -Value $rule.MailboxOwnerID | |
$RulesD| Add-Member -MemberType NoteProperty -Name ForwardTo -Value "N/A" | |
$RulesD| Add-Member -MemberType NoteProperty -Name RedirectTo -Value $($rule.RedirectTo | % {$($_.split("[")[0]).Replace('"',"")}) | |
$RulesDATA+=$rulesD } | |
} | |
} | |
} | |
$RulesDATA | Export-Csv "Forwarding-Rules-Report.csv" -notype |
- Get link
- X
- Other Apps
Comments
Post a Comment