Created
April 25, 2024 12:12
-
-
Save LudovicOmarini/f70b345da16617dbb16be65647cf0282 to your computer and use it in GitHub Desktop.
This script manages Exchange Online calendar permissions for one or more users.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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 and install it if necessary | |
if (-not (Get-Module -Name ExchangeOnlineManagement -ListAvailable)) { | |
Install-Module ExchangeOnlineManagement -Force -AllowClobber | |
} | |
# Connect to Exchange Online | |
Connect-ExchangeOnline | |
# Ask the user to provide a list of email addresses of calendar owners | |
$calendarOwners = (Read-Host "Enter the email address(es) of the calendar owner(s) (separated by commas)") -split ',' | |
# Display the current permissions on users' calendars | |
Write-Host "`nList of permissions on users' calendars`n" -ForegroundColor Yellow | |
foreach ($calendarOwner in $calendarOwners) { | |
$identity = "$($calendarOwner):\Calendar" | |
Write-host "---------------`n$calendarOwner" -ForegroundColor Cyan | |
# Display the current permissions on the calendar | |
Get-MailboxFolderPermission -Identity $identity | Select-Object User, AccessRights | Format-Table -AutoSize | Out-String | Write-Host | |
} | |
# Get the user identifier and the action to perform | |
$user = Read-Host "Enter the email address or the Full Name of the user to add, modify, or remove" | |
$action = Read-Host "Enter the action to perform on the calendar(s): Add, Remove, or Update" | |
# Ask for permissions to grant only for Update or Add | |
if ($action -eq "Update" -or $action -eq "Add") { | |
Write-Host "The list of parameter values is available at the following link: https://learn.microsoft.com/en-us/powershell/module/exchange/add-mailboxfolderpermission?view=exchange-ps#-accessrights`n" | |
Write-Host "You can choose multiple roles or permissions by separating them with a comma." | |
$permissionLevel = Read-Host "Choose the desired role(s)/permissions (Author, Contributor, Editor, NonEditingAuthor, Owner, PublishingAuthor, PublishingEditor, Reviewer...)" | |
} | |
# Modify permissions on users' calendars according to the specified action | |
foreach ($calendarOwner in $calendarOwners) { | |
$identity = "$($calendarOwner):\Calendar" | |
Write-host "---------------`n$calendarOwner" -ForegroundColor Cyan | |
# Update permissions | |
if ($action -eq "Update") { | |
Write-Host "Executing Update command..." -ForegroundColor Magenta | |
Set-MailboxFolderPermission -Identity $identity -User $user -AccessRights $permissionLevel | |
} | |
# Add permissions | |
elseif ($action -eq "Add") { | |
Write-Host "Executing Add command..." -ForegroundColor Magenta | |
Add-MailboxFolderPermission -Identity $identity -User $user -AccessRights $permissionLevel | |
} | |
# Remove permissions | |
elseif ($action -eq "Remove") { | |
Write-Host "Executing Remove command..." -ForegroundColor Magenta | |
Remove-MailboxFolderPermission -Identity $identity -User $user -Confirm:$false | |
} | |
# Display permissions after modification | |
Get-MailboxFolderPermission -Identity $identity | Select-Object User, AccessRights | Format-Table -AutoSize | Out-String | Write-Host | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment