Microsoft doesn't make it easy for admins to check whether a shared mailbox is added to a user using automapping - meaning it pops up automatically in the actual user's Outlook - or not.
This script is for exporting all the mailboxes that have users automapped with FullAccess rights
# List all mailboxes that are automapped to users Get-ADUser -Filter * -Properties msexchdelegatelistlink | ? {$_.msexchdelegatelistlink -ne ""} | %{ $mb = $_.UserPrincipalName # Expand automapped user list $_.msexchdelegatelistlink | %{ $user = (get-aduser $_).UserPrincipalName [pscustomobject]@{"Mailbox" = $mb; "User" = $user} } }
If you want to export the list to a CSV file, use the following script:
# List all mailboxes that are automapped to users Get-ADUser -Filter * -Properties msexchdelegatelistlink | ? {$_.msexchdelegatelistlink -ne ""} | %{ $mb = $_.UserPrincipalName # Expand automapped user list $_.msexchdelegatelistlink | %{ $user = (get-aduser $_).UserPrincipalName [pscustomobject]@{"Mailbox" = $mb; "User" = $user} | export-csv AutomappedMailboxesList.csv -Append -NoTypeInformation } }
PJ IT says
Thank you for the script, here is a version that also handles getting the SamAccountName in the list should you have a universal email enabled group tied to the msexchdelegatelistlink attribute
Get-ADUser -Filter * -Properties msexchdelegatelistlink | ? {$_.msexchdelegatelistlink -ne “”} | % {
$mb = $_.UserPrincipalName
$sn = $mb.Split(“@”)[0].Trim();
# Expand automapped user list
$_.msexchdelegatelistlink | %{
$user = “”;
Try { $user = (Get-ADUser -Identity $_).UserPrincipalName; } Catch {};
If ( !$user ) { $user = ($_).Split(“,”)[0].Split(“=”)[1].Trim(); };
[pscustomobject]@{“Mailbox” = $mb; “User” = $user};
}
};
PJ IT says
You can remove the $sn = $mb.Split(“@”)[0].Trim(); variable line. I was testing various things and forgot to take that out before posting. Feel free to not even post this comment if it’s not helpful or if it is, add to the post and no need to show the comment. I put my work address in on accident anyway so hopefully you don’t post email addresses which I assume you don’t but the comment being posted is not important to me, I just wanted to show you I had to tweak to list the group SamAccountName in with the list.
Jarrod says
Hi Zsolt,
You forgot to add -Append to the end of the export-csv command. As it currently stands, you only export the last found record.
Zsolt Agoston says
Hi Jarrod,
Nice catch, it’s fixed now. Thank you.