# Script to Fetch All users with FullAccess/GrantSendOnBehalfTo Right to other users mailbox

# Writien By Alberto Igbinedion



# Get all mailboxes From SpreadSheet
$Delegates = Import-Csv "\\nopmgr1\g$\CM Storage\Migration Batches\Done CSV\Migration_Batch1_Batch3_Combined.csv"


clear-host
 
write-host Please choose an option below:
 
 
write-host '1) Get MailBox From SpreadSheet'
 
write-host '2) Get Mailbox From Server'
 
write-host '3) Exit' -ForegroundColor Red
 
write-host
 
$opt = Read-Host "Select an option [1 - 3]"


 
switch ($opt) {


1 {
        $MailboxPermission = @()
        Foreach ($Item in $delegates) 
        { 
            $MailboxPermission += (Get-Mailbox $Item.ImportName | Get-MailboxPermission)
        } 
   }

2 {
    $MailboxPermission = (Get-Mailbox -resultsize unlimited | Get-MailboxPermission)
   }
 
 

3 {
    }
 
 }
 
 if($MailboxPermission)
 {
    $MailboxPermission | ? { ($_.AccessRights -eq "FullAccess") -and ($_.user -like "*ons\*")-and ($_.AccessRights -notlike "*read*", "*DeleteItem*" , "*Change*") `
        -and -not ($_.user -like "*ONS\laker2_admin*" -or $_.user -like "*ONS\NotesAdmin*") -and -not ($_.Alias -like "*laker2_admin*") } | `
        select @{Name='Alias.Pa';expression={(Get-mailbox $_.User).Alias}} , accessrights, @{Name='Alias.Manager';expression={(Get-mailbox $_.identity).Alias}},@{Name='Alias.Pa.GrantSendOnBehalfTo';expression={((Get-mailbox $_.Identity).GrantSendOnBehalfTo).alias}} |
        
         Export-Csv C:\Scripts\Output\SendonBehaft.csv -NoTypeInformation -Append
 }

 

 
            


#E.G ---- @{Name="Kbytes";Expression={$_.Length / 1Kb}}
# @{} is a Hash table
#  Name="Kbytes" is name of property self created
# Expression={$_.Length / 1Kb} is Expression script block
               




