In my lab, I was wanting to see which mailboxes had Send On Behalf Permissions assigned and instead of going through each mailbox and looking at the delegation tab in the Exchange Admin Center (EAC), I put together a script to get this information for me.

The script takes a few minutes to run as it checks each mailbox and then displays the information as shown below:

PowerShell displaying all mailboxes with SendOnBehalfRights

Script

The script is pretty straight forward and you do not need to make any changes to it unless you want to see more information in the results section, here is the script:

# Import the Exchange module
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

# Get all mailboxes with SendOnBehalf permissions
$allMailboxes = Get-Mailbox -ResultSize Unlimited

# Create an array to store results
$results = @()

# Loop through each mailbox
foreach ($mailbox in $allMailboxes) {
    # Get SendOnBehalf permissions
    $sendOnBehalfPermissions = Get-Mailbox -Identity $mailbox.Identity | Where {$_.GrantSendOnBehalfTo -ne $null}

    # If SendOnBehalf permission exists, add to results
    if ($sendOnBehalfPermissions) {
        $result = [PSCustomObject]@{
            DisplayName      = $mailbox.DisplayName
            Alias            = $mailbox.Alias
            PrimarySmtpAddress = $mailbox.PrimarySmtpAddress
            GrantSendOnBehalfTo     = $mailbox.GrantSendOnBehalfTo
        }
        $results += $result
    }
}

# Display results in a table
$results | Format-Table -AutoSize

The Exchange Snapin is loaded as this will run from PowerShell ISE as well and give you the same information just like running it from an Exchange Server directly.

Hope it helps.

    wpChatIcon

    Discover more from Everything-PowerShell

    Subscribe now to keep reading and get access to the full archive.

    Continue reading