[Powershell Script] Get Full Mailbox Access Permission report from office 365 Mailboxes

Get Full Mailbox Access Permission Report 


This script will get you Full Mailbox Access permission from all the users in the organization and then export the results in the CSV file.

This script is suitable for a small environment, maintains the logging to restart the script in case of failure.


######################################################
# Full Mailbox Permission backup
# Author : Sunil Chauhan
# Email: sunilkms@gmail.com
# This script takes backup of Full Mailbox permission.
######################################################
#----------------------------------------
# Edit Mail Notification Settings Here
#-----------------------------------------
$mail=@{
  To = "sunil@domain.com"
  From = "sunil@domain.com"
  SMTPServer = "smtp.office365.com"  
  }

#-------------------------------------------------------------
# you can customize the current msg as per your requirement.
#-------------------------------------------------------------
$body =@"
Hi,


Please Find the Attached Full Mailbox Access Report for $(get-date -Format MM/dd/yyyy).


Thanks,
Report Admin
"@

#---------------------------------------------------------
# Log
#---------------------------------------------------------
$LogFile = "FullMailbox-SendAs-Report-Logs.log"
Write-host "Getting All Mailboxes in the org.." -f Yellow
Add-content -path $logFile -value "$(get-date -Format MM/dd/yyyy-hh:mm:ss) :Starting.."
Add-content -path $logFile -value "$(get-date -Format MM/dd/yyyy-hh:mm:ss) :Getting All Mailboxes in the org.."

#Fetch All the mailbox
$AllMailbox = Get-Mailbox -ResultSize unlimited
write-host "Getting FullAccess Permission for All Mailboxes"
Add-content -path $logFile -value "$(get-date -Format MM/dd/yyyy-hh:mm:ss) :Getting FullMailbox Permission..."

$data = @()
foreach ($user in $allMailbox)
                            {
                            Add-content -path $logFile -value "$(get-date -Format MM/dd/yyyy-hh:mm:ss) : Checking:$($user.PrimarySmtpAddress)"
                            $permission=Get-MailboxPermission $user.alias | ? {$_.isinherited -ne "True" -and $_.User -notlike `
                            "S-1-5*" -and $_.user -notlike "*Self"} | select Identity,`
                            @{Label="SMTPAddress";Expression={$user.PrimarySmtpAddress}},user,AccessRights,`
                            @{Label="RecipientType";Expression={$User.RecipientTypeDetails}}
                            $data+=$permission
                            }

#Export report
$FulMbxReport= "FullMailboxAccessPermission-" + $(get-date -Format MM-dd-yyyy) + ".csv"
$data | Export-csv $FulMbxReport -Notype
Add-content -path $logFile -value "$(get-date -Format MM/dd/yyyy-hh:mm:ss) :FullMailbox Permission reported has been prepared."

"Sending Email"
$Subject = "Full Access Permission Backup for $(get-date -Format MM/dd/yyyy) "
Send-MailMessage -from $mail.From -to $mail.to -subject $Subject -Body $body -SmtpServer $mail.SMTPServer -Attachment $FulMbxReport
Add-content -path $logFile -value "$(get-date -Format MM/dd/yyyy-hh:mm:ss) :Full Mailbox Report Was Sent."

Comments