Wednesday, 18 December 2024

EXO Mailbox Permission


$output = [system.collections.arraylist]@()
$output.Clear()
#$upnn = "user@email.com"
$upn = Get-mailbox -recipienttypedetails Sharedmailbox
 
$ErrorActionPreference = "SilentlyContinue"
$upn | foreach{  
    $u = $_.userprincipalname   
 
    [string[]]$FA = (Get-MailboxPermission $u).user #|%{($_ -split '["\\"]')[1]}|%{($_ -split '[,]')}
    [string[]]$SA = (Get-RecipientPermission $u).trustee #|%{($_ -split '["/"]')[2]}#|%{($_ -split '[","]')}
    [string[]]$SOB = (Get-Mailbox $u).GrantSendOnBehalfTo
 
    $Count = ($FA,$Sob,$SA | ForEach-Object {$_ | Measure-Object} | Select-Object Count | Sort-Object count -Descending | Select-Object -First 1).count
    $currentindex = 0
    do
    {
        if($FA[$currentindex]){$CurrentFA = $FA[$currentindex]}
        else{$CurrentFA = " "}
 
        if($SA[$currentindex]){$CurrentSA = $SA[$currentindex]}
        else{$CurrentSA = " "}
 
        if($SOB[$currentindex]){$CurrentSOB = $SOB[$currentindex]}
        else{$CurrentSOB = " "}
 
        $Result = [pscustomobject][ordered] @{
            Type = $_.RecipientTypeDetails
            Mailbox = $u
            FullAccess = $CurrentFA
            SendAs = $CurrentSA
            SendOnBehalf = $CurrentSOB
        }
        $output.Add($Result)
        $Result |Export-Csv "D:\SUMANT\Output\27-Jul-Shared_MailboxPermission.csv" -NoTypeInformation -Append
        $currentindex ++
    }
    until($currentindex -eq $Count )
}
 



--------------------------------- End --------------------------------- 

No comments:

Post a Comment