Sets calendar sharing permissions across all M365 user mailboxes via Exchange Online, while explicitly excluding the CEO and a configurable group of executives.
| Requirement | Details |
|---|---|
| PowerShell | 5.1+ or PowerShell 7+ |
| Module | ExchangeOnlineManagement (auto-installed if missing) |
| Admin Role | Exchange Administrator or Global Administrator |
| Auth | Modern Auth / MFA-compatible (interactive browser login) |
Open Set-CalendarSharing.ps1 and update these two sections:
$ExcludedUsers = @( "[email protected]", "[email protected]", "[email protected]" # Add or remove executives here )
$SmtpServer = "smtp.office365.com" $SenderEmail = "[email protected]"
.\Set-CalendarSharing.ps1 -WhatIf
Shows exactly what would change. No mailboxes are modified.
.\Set-CalendarSharing.ps1 -NotifyEmail "[email protected]"
.\Set-CalendarSharing.ps1 -SharingPermission "AvailabilityOnly" -NotifyEmail "[email protected]"
| Value | What it shares |
|---|---|
AvailabilityOnly |
Free/Busy only |
LimitedDetails |
Free/Busy + subject & location (default) |
Reviewer |
Full read access to calendar items |
Editor |
Read and write access |
Author |
Read, write, create |
PublishingEditor |
Full control |
- Checks prerequisites — Verifies/installs the Exchange Online module
- Connects — Interactive modern auth login (MFA-supported)
- Retrieves mailboxes —
Get-Mailbox -RecipientTypeDetails UserMailbox - Partitions — Separates target users from excluded executives
- Validates exclusions — Warns if any configured exclusion UPN is not found in Exchange
- Applies permissions —
Add-MailboxFolderPermissionorSet-MailboxFolderPermission - Verifies — Re-reads permissions post-change to confirm they applied
- Exclusion audit — Confirms exec calendars were not touched
- Reports — Writes a
.logfile and a.csvreport - Notifies — Emails the admin with a summary (if
-NotifyEmailprovided) - Disconnects — Cleanly closes the Exchange Online session
| Scenario | Behaviour |
|---|---|
| Module missing | Auto-installs; exits with error + email if it fails |
| Cannot connect to Exchange | Exits with error + email notification |
Get-Mailbox fails |
Exits with error + email notification |
| Per-mailbox permission failure | Logged as ERROR; script continues to next mailbox |
| Unexpected script crash | trap {} block catches it, logs, emails admin, disconnects |
| Exclusion UPN not found in Exchange | Logs a WARN (does not abort) |
| Permission mismatch after apply | Logs a WARN during verification pass |
All output is written to a Logs\ subfolder next to the script.
| File | Contents |
|---|---|
CalendarSharing_YYYYMMDD_HHmmss.log |
Full timestamped run log |
CalendarSharing_Report_YYYYMMDD_HHmmss.csv |
Per-mailbox result table |
"Connect-ExchangeOnline is not recognized"
Run: Install-Module ExchangeOnlineManagement -Scope CurrentUser -Force
Script blocked by execution policy
Run: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Email notification not sending
Confirm $SenderEmail is a valid M365 mailbox and your admin account has Send-As rights.