Forum Discussion
PS export to see if users are sharing their calendar details in Outlook
Hi all, and happy Friday!
Just learned there's a PowerShell community so figured I'd save myself from rabbit hole research online and start here.
I am wanting to create an export/report of all user calendars in our org so I can see which of them are choosing to show their details. We recently had an incident where a c-level exec was unknowingly sharing the details of their calendar instead of just showing "Busy" so I figured we should advise others doing the same. I can view my own by right-clicking my calendar > Properties > Permissions.
What PS cmd would be best to get an export of the same for all user calendars in our org? Thank you in advance!
- kevkellyBrass Contributor
Hi mdcastorena
As LeonPavesic has already highlighted, you'll want to use the cmdlet Get-MailboxFolderPermission to view folder-level permissions in mailboxes
A simple one-liner that would get the calendar permissions for a single mailbox would be:
Get-MailboxFolderPermission -Identity <mailbox_id>:\Calendar
- mdcastorenaBrass ContributorPerfect, thank you. Now how would I loop through a list of ALL mailboxes (such as CSV file listing all email addresses), or just have it display all mailboxes instead of requiring an Identity?
- kevkellyBrass Contributor
LeonPavesic already supplied an extended example of how you could loop through all mailboxes
Given a CSV file that contains say a list of the PrimarySmtpAddress that you want to check Calendar permissions for, a simple script that would loop through each address might look like:
$mailboxes = Import-Csv -Path <path_to_csv_file> foreach($mailbox in $mailboxes){ Get-MailboxFolderPermission -Identity "$($mailbox.PrimarySmtpAddress):\Calendar" -ErrorAction SilentlyContinue | Select-Object Identity, User, AccessRights, SharingPermissionFlags }
The above is a simplified example, ideally you'd add some error handling to this script and export the results to a file rather than the console
If you wanted to query all mailboxes and not use a CSV file as the input, then you could change the $mailboxes variable to:
$mailboxes = Get-Mailbox -ResultSize Unlimited
- LeonPavesicSilver Contributor
Hi mdcastorena,
It's great to hear that you're turning to the PowerShell community for assistance. I can try to help you with creating a PowerShell script to export and analyze calendar sharing settings for users in your organization:# Connect to Exchange Online
$credential = Get-Credential
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession -DisableNameChecking# Get a list of all user mailboxes
$mailboxes = Get-Mailbox -ResultSize Unlimited# Initialize an empty array to store the results
$calendarSharingDetails = @()# Loop through each mailbox
foreach ($mailbox in $mailboxes) {
$mailboxEmail = $mailbox.PrimarySmtpAddress# Get calendar sharing permissions for the mailbox
$calendarPermissions = Get-MailboxFolderPermission -Identity "$mailboxEmail:\Calendar"# Loop through each calendar permission and extract the relevant details
foreach ($permission in $calendarPermissions) {
$calendarSharingDetail = New-Object PSObject
$calendarSharingDetail | Add-Member -MemberType NoteProperty -Name "Mailbox" -Value $mailboxEmail
$calendarSharingDetail | Add-Member -MemberType NoteProperty -Name "User" -Value $permission.User
$calendarSharingDetail | Add-Member -MemberType NoteProperty -Name "AccessRights" -Value $permission.AccessRights$calendarSharingDetails += $calendarSharingDetail
}
}# Export the results to a CSV file
$calendarSharingDetails | Export-Csv -Path "CalendarSharingDetails.csv" -NoTypeInformation# Disconnect from Exchange Online
Remove-PSSession $exchangeSession
You'll need the Exchange Online PowerShell module installed to run this script.
About the Exchange Online PowerShell V2 module and V3 module | Microsoft Learn
Once you have the script ready, save it with a .ps1 extension (e.g., CalendarSharingReport.ps1), and then execute it in a PowerShell environment in a path in which the script was saved..
.\CalendarSharingReport.ps1
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Kindest regards
Leon Pavesic