====== Postfächer mit Weiterleitung ermitteln ======
Mit folgendem Script lassen sich alle Exchange-Postfächer ermitteln, die in den Nachrichtenübermittlungseinstellungen eine Weiterleitung eingetragen haben:
$MailboxesWithForwarding = get-mailbox -filter {forwardingAddress -ne $NULL}
foreach ($Mailbox in $MailboxesWithForwarding)
{
$ext = "";
$MailContact = $NULL;
$MailContact = Get-MailContact -Identity $Mailbox.ForwardingAddress -erroraction 'silentlycontinue'
if ($MailContact -ne $NULL)
{
$ext = $MailContact.ExternalEmailAddress.tostring()
} else
{
$MailContact = get-mailbox -Identity $Mailbox.ForwardingAddress -erroraction 'silentlycontinue'
if ($MailContact -eq $NULL)
{
$MailContact = get-dynamicdistributiongroup $Mailbox.ForwardingAddress -erroraction 'silentlycontinue'
if ($MailContact -eq $NULL)
{
$MailContact = get-distributiongroup $Mailbox.ForwardingAddress
}
}
}
$ext = $MailContact.PrimarySMTPAddress.tostring()
$Mailbox.PrimarySMTPAddress.tostring() + ";" + $Mailbox.LinkedMasterAccount + ";" + $ext
}
oder etwas einfacher:
Write-Host "Displayname;PrimarySmtpAddress;Forwardingaddress"
foreach ($MBox in get-mailbox -resultsize unlimited | ?{$_.Forwardingaddress -ne $null})
{
try
{
$adresse = Get-Contact $MBox.forwardingaddress -Erroraction Stop;
$adresse = $adresse.WindowsEmailAddress;
Write-Host $MBox.displayname";"$MBox.Primarysmtpaddress";"$adresse
}
catch
{
$adresse = "Keine Weiterleitung nach Extern"
}
}
{{tag>[Exchange Powershell Weiterleitungen]}}