Friday, 13 September 2019

Get Calendar Permissions for All Users in Office 365

In Exchange, the calendar data located in a special folder (Calendar) under the user's mailbox. We can use the Exchange powershell cmdlet Get-MailboxFolderPermission to list all permissions that are configured in a Calendar folder.

Before proceed run the below commands to connect Exchange Online (EXO) powershell.
$365Logon = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $365Logon -Authentication Basic -AllowRedirection
Import-PSSession $Session

Get permissions for a single user in a user's calendar :

The below command returns permission entries for an individual user in a specific user's mailbox calendar. Run the below command after replacing the user "" and mailbox identity "" with your user id and mailbox id.
Get-MailboxFolderPermission -Identity "\Calendar" -User ""

Get all permissions in a user's calendar :

You have to exclude the parameter "-User" to list all user permissions in a specific user's mailbox. The below command list all users who have permission in Alex's mailbox calendar.
Get-MailboxFolderPermission -Identity "\Calendar"

Get all permissions in all users calendar :

To extract permissions from all users' calendars, first, we have to fetch all mailboxes with the Get-Mailbox cmdlet and pipe the result to Get-MailboxFolderPermission cmdlet to get the mailbox folder permissions.
Get-Mailbox -ResultSize Unlimited | ForEach {Get-MailboxFolderPermission -Identity "$($_.PrimarySMTPAddress):\Calendar" } | Select Identity,User,AccessRights
The above command returns all permission entries in all users' calendar, the result also includes the default permissions "Default" & "Anonymous". You can exclude the "Default" & "Anonymous" entries with Where-Object filter.
Get-Mailbox -ResultSize Unlimited | ForEach {Get-MailboxFolderPermission -Identity "$($_.PrimarySMTPAddress):\Calendar" } | Where-Object {$_.User.DisplayName -ne "Default" -and $_.User.DisplayName -ne "Anonymous"} | Select Identity,User,AccessRights

Export all users calendar permissions in all mailboxes to CSV file :

$allMailboxes = Get-Mailbox -ResultSize Unlimited | Select-Object -Property Displayname,PrimarySMTPAddress
$totalMailboxes = $allMailboxes.Count
$i = 1 
$allMailboxes | ForEach-Object {
$mailbox = $_
Write-Progress -activity "Processing $($_.Displayname)" -status "$i out of $totalMailboxes completed"
$folderPerms = Get-MailboxFolderPermission -Identity "$($_.PrimarySMTPAddress):\Calendar"
$folderPerms | ForEach-Object {
$Result += New-Object PSObject -property @{ 
MailboxName = $mailbox.DisplayName
User = $_.User
Permissions = $_.AccessRights
$Result | Select MailboxName, User, Permissions |
Export-CSV "C:\\CalendarPermissions.CSV" -NoTypeInformation -Encoding UTF8


No comments:

Post a Comment