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]$userToRemoveAccess #[String] is the type of parameter. $userToAddAccess is the name of the parameter. ) # Connect to Exchange Online Connect-ExchangeOnline #Get a list of all user mailboxes (excluding shared mailboxes) $mailboxes = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Where-Object { $_.RecipientTypeDetails -ne "SharedMailbox" } #Iterate through each mailbox and remove '$userToAddAccess' access to the calendar foreach ($mailbox in $mailboxes) { $calendarEmail = $mailbox.UserPrincipalName + ":\Calendar" #Creates the calendar identity Remove-MailboxFolderPermission -Identity $calendarEmail -User $userToRemoveAccess -Confirm:$false Write-Host "$mailbox" Get-MailboxFolderPermission -Identity $calendarEmail } # Disconnect from Exchange Online Disconnect-ExchangeOnline