Furlan86
Furlan86

Reputation: 13

How to get all "Send on behalf to" permissions for a specific user on Exchange 2016?

I found on another website a PowerShell script that lists all mailboxes for which a specific user has access rights of any kind, although I still had to make some changes to it to make it suitable for mailbox searches on Exchange Server 2016. Well, this script works like a charm for "Full Access" and/or "Send as" permissions, while it doesn’t seem to work properly for "Send on behalf to" permissions: in fact, when searching for all mailboxes for which a specific user surely has "Send on behalf to" permissions, the “SendOnBehalf” column incorrectly reports the value “False”.

Below is the script modified by me:

$User = "<UserPrincipalName>"
$Mailboxes = Get-Mailbox -ResultSize Unlimited

foreach ($Mailbox in $Mailboxes)
{
    # Check Full Access Permission
    $FullAccess = $null
    $FullAccess = Get-MailboxPermission -Identity $Mailbox.Identity | Where-Object { ($_.User -like "*$User*") -and ($_.AccessRights -eq "FullAccess") }
    
    # Check Send On Behalf Permission
    $SendOnBehalf = $null
    if ($Mailbox.GrantSendOnBehalfTo.User -like "*$User*") {
        $SendOnBehalf = $User
    }

    # Check Send As Permission
    $SendAs = $null
    $SendAs = Get-ADPermission $Mailbox.Identity | Where { ($_.User -like "*$User*") -and ($_.ExtendedRights -like “*Send-As*”) }

    if ($FullAccess -or $SendOnBehalf -or $SendAs)
    {
        $Output = New-Object -TypeName PSObject
        $Output | Add-Member -Type NoteProperty -Name "Mailbox" -Value $Mailbox.Identity
        $Output | Add-Member -Type NoteProperty -Name "FullAccess" -Value $($FullAccess -ne $null)
        $Output | Add-Member -Type NoteProperty -Name "SendOnBehalf" -Value $($SendOnBehalf -ne $null)
        $Output | Add-Member -Type NoteProperty -Name "SendAs" -Value $($SendAs -ne $null)
        Write-Output $Output
    }
}

Below is an example of output where in the case of the second result the value "False" is absolutely incorrect:

enter image description here

Upvotes: 0

Views: 69

Answers (0)

Related Questions