Skip to content

Instantly share code, notes, and snippets.

@LudovicOmarini
Last active December 2, 2024 10:36
Show Gist options
  • Select an option

  • Save LudovicOmarini/f70b345da16617dbb16be65647cf0282 to your computer and use it in GitHub Desktop.

Select an option

Save LudovicOmarini/f70b345da16617dbb16be65647cf0282 to your computer and use it in GitHub Desktop.
This script manages Exchange Online calendar permissions for one or more users.
<#
.SYNOPSIS
This script manages Exchange Online calendar permissions for one or more users.
.DESCRIPTION
This script first checks if the ExchangeOnlineManagement module is installed and installs it if necessary.
Then, it connects to Exchange Online and retrieves the current permissions on the specified users' calendars.
The user can then choose to add, update, or remove permissions on the calendars, specifying the target user and the permissions to grant.
The changes are then made to the relevant calendars.
.EXAMPLE
.\O365_Manage_Calendar_Rights.ps1
.LINK
List of values for the -AccessRights parameter for the *-Mailboxfolderpersmission command
https://learn.microsoft.com/en-us/powershell/module/exchange/add-mailboxfolderpermission?view=exchange-ps#-accessrights
#>
# Check if the ExchangeOnlineManagement module is already installed
if (-not (Get-Module -Name ExchangeOnlineManagement -ListAvailable)) {
# Install the ExchangeOnlineManagement module if it is not already installed
Install-Module ExchangeOnlineManagement -Force -AllowClobber
}
# Import the ExchangeOnlineManagement module
Import-Module ExchangeOnlineManagement
# Connect to Exchange Online
Connect-ExchangeOnline
# Prompt the user to provide a list of calendar owners' email addresses
$calendarOwners = Read-Host "Enter the email addresses of calendar owners (separated by semicolons)"
# Convert the list into an array by splitting email addresses using semicolons
$calendarOwners = $calendarOwners -split ';'
# Get the identifier of the user ("Default" should be entered to set default calendar permissions)
$user = Read-Host "Enter the email address of the user to add, modify, or remove"
# Get the action to perform: Update (modify), Add (grant), or Remove (revoke) permissions
$action = Read-Host "Enter the action to perform: Update (modify), Add (grant), or Remove (revoke) permissions"
# Define the permissions to grant to the user on the calendar
$permissionLevel = Read-Host "Choose from: Owner, PublishingEditor, Editor, PublishingAuthor, Author, NonEditingAuthor, Reviewer, Contributor, AvailabilityOnly (leave blank if removing)"
# Loop through each calendar owner and apply the specified changes
foreach ($calendarOwner in $calendarOwners) {
# Note: The mailbox folder may be localized (e.g., "Calendar" in English, "Calendrier" in French).
# Update the following line if needed: $identity = "$($calendarOwner):\Calendrier"
$identity = "$($calendarOwner):\Calendar"
# Update permissions
if ($action -eq "Update") {
Set-MailboxFolderPermission -Identity $identity -User $user -AccessRights $permissionLevel
}
# Add permissions
elseif ($action -eq "Add") {
Add-MailboxFolderPermission -Identity $identity -User $user -AccessRights $permissionLevel
}
# Remove permissions
elseif ($action -eq "Remove") {
Remove-MailboxFolderPermission -Identity $identity -User $user
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment