This script is designed to be used with the script password encryption for Office 365. See here https://www.techshizz.com/post/powershell-script-password-ecryption-for-multi-site-administration for more info.
Import-Module MSOnline $rootpath = (get-item '.' ).parent.FullName $clientname = Get-Content "$rootpathclient.txt" -Raw $user = Get-Content "$rootpathUserID.txt" $PasswordFile = "$rootpathPassword.txt" $KeyFile = "C:ICUAES.key" $key = Get-Content $KeyFile $UserCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key) $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection Write-Host "Connecting to Exchange Online for $clientname" Import-PSSession $Session function Menu{ $menu=@" 1 Add Calendar Permissions 2 Remove Calendar Permissions 3 Check Calendar Permissions S Search for an email address Q Quit Select a task by number or Q to quit "@ Write-Host "Calendar Permissions" -ForegroundColor Cyan $r = Read-Host $menu Switch ($r) { "1" { $emailaddress = Read-Host "Enter the email of the mailbox to provide Calendar access to" $accesslevel = Read-Host "Type the level of access you want to add: Author Contributor Editor None NonEditingAuthor Owner PublishingEditor PublishingAuthor Reviewer AvailabilityOnly LimitedDetails" $deligate = Read-Host "Enter the email address of the deligate" Add-MailboxFolderPermission –Identity $emailaddress":Calendar" –User $deligate –AccessRights $accesslevel Write-Host "Adding Mailbox Calendar Permissions..." Menu } "2" { $emailaddress = Read-Host "Enter the email of the mailbox who currently has access that you want to remove" $deligate = Read-Host "Enter the email address of the mailbox to which the user has access to" Write-Host "Removing Mailbox Calendar Access..." Remove-MailboxFolderPermission –Identity $emailaddress":Calendar" –User $deligate Menu } "3" { $emailaddress = Read-Host "Enter the email address that you want to check permissions for" Write-Host "Loading..." Get-MailboxFolderPermission -Identity $emailaddress":Calendar" | Format-Table Menu } "S" { $search = Read-Host "Enter Name to Search" Write-Host "Searching..." Get-Mailbox | Where-Object { $_.Name -Like "*$search*" } | Select-Object DisplayName,PrimarySmtpAddress | Format-Table Menu } "Q" { Write-Host "Removing any PS Sessions..." -ForegroundColor Green Get-PSSession | Remove-PSSession Exit } default { Write-Host "Choose a valid option... Fool!" -ForegroundColor Yellow } } #end switch } Menu