Param( #Defines Parameters that will be used within this script. [Parameter(Mandatory=$true)] #This is an attribute applied to the parameter. It specifies that a parameter is required. [string]$userToAddAccess #[String] is the type of parameter. $userToAddAccess is the name of the parameter. ) Connect-ExchangeOnline #This grabs all USER mailboxes and not SHARED $mailboxes = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Where-Object { $_.RecipientTypeDetails -ne "SharedMailbox" } #This iterates through each mailbox using a FOR Loop and grants '$userToAddAccess' full access to the user mailbox ($mailboxEmail) foreach ($mailbox in $mailboxes) { $mailboxEmail = $mailbox.UserPrincipalName Add-MailboxPermission -Identity $mailboxEmail -User $userToAddAccess -AccessRights FullAccess -AutoMapping $false #Prints a list of the current delegation of user's mailbox. This is so you can check delegation as the script works through the list of user mailboxes Get-MailboxPermission -Identity $mailboxEmail | Where-Object { $_.AccessRights -like "FullAccess" } } # Disconnect from Exchange Online Disconnect-ExchangeOnline