====== Genutzte Linked-Postfächer ohne Nutzeranmeldung ====== Filtert alle linked-Postfächer heraus, für die es eine Weiterleitung zu einem externen Postfach gibt und für die es in der Stammdomäne keine Benutzeranmeldung gibt. Das wäre ein Hinweis auf ein Benutzer und Postfach, die genutzt werden, aber man sieht es nicht an typischen Werten wie LastLogonDate o.ä. "" > out.csv "" > error.log $mailboxes = Get-Mailbox -Filter {ForwardingAddress -ne $null} $contacts = Get-MailContact -filter {ExternalEMailAddress -like "*@externalDomain.com"} $credDomainA = get-credential -message "Anmeldedaten für DomainA" $credDomainB = get-credential -message "Anmeldedaten für DomainB" foreach ($mailbox in $mailboxes) { $externalAddress = ""; $found = $false; foreach ($contact in $contacts) { if ($contact.Identity -eq $mailbox.ForwardingAddress) { $found = $true; $externalAddress = $contact.ExternalMailAddress; } } if ($found -eq $true) { $ldap = $false; $userarray = $mailbox.LinkedMasterAccount.Split("\"); if ($userarray[0] -eq "DomainA") {$dc = "controllerA.domaina.loc"; $cred = $credDomainA; $ldap = $true} if ($userarray[0] -eq "DomainB") {$dc = "controllerB.domainb.loc"; $cred = $credDomainB; $ldap = $true} if ($ldap -eq $true) { $aduser = get-aduser $userarray[1] -properties lastlogonDate -server $dc -Credential $cred; $ext = $contacts | ?{$_.Identity -eq $mailbox.ForwardingAddress} $aduser.SamAccountName + ";" + $aduser.LastLogonDate + ";" + $ext >> out.csv $aduser.SamAccountName + ";" + $aduser.LastLogonDate + ";" + $ext } else { "Keine Zuordnung für Postfach " + $mailbox.PrimarySMTPAddress + "?" >> error.log "Keine Zuordnung für Postfach " + $mailbox.PrimarySMTPAddress + "?" } } } {{tag>[Exchange Powershell]}}