GiveUserAccessAllCalendars.ps1

Gives a specified user read-only access to the calendars of all user mailboxes within Exchange. This excludes Shared Mailboxes.

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 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 grant '$userToAddAccess' access to the calendar
foreach ($mailbox in $mailboxes) {
    $calendarEmail = $mailbox.UserPrincipalName + ":\Calendar"  #Creates the calendar identity
    Add-MailboxFolderPermission -Identity $calendarEmail -User $userToAddAccess -AccessRights Reviewer
    Write-Host "$mailbox"
    Get-MailboxFolderPermission -Identity $calendarEmail
}

# Disconnect from Exchange Online
Disconnect-ExchangeOnline

Loading