Get default calendar name for Mailbox Folder Permisssions Exchange PowerShell

Set-MailboxFolderPermission -Identity [email protected]:\calendar -AccessRights FullAccess

At work I have a customer who is spread out over 30 different countries. This also causes some fun issues, such as the time zones, language barrier, or very specifically the calendar folder name in the mailbox has the default language name.

In this blog post I will tell you more about the calendar folder name and how you can easily adjust the folder permissions in bulk via PowerShell.


Let’s go through it step by step.

Below I will explain step by step how you can retrieve the calendar folder per user, and what you can ultimately do with it.

We use the following PowerShell Commands:

These commands are in the Exchange Online module.

I’m going to explain parts of the commands. If you want to know more you can follow the link to Microsoft Docs.


How do I find the right calendar folder name per mailbox?

The following command shows you all folders that are of the calendar type. This also includes the holidays and calendars birthdays.

Get-mailbox -Identity [email protected] | Get-MailboxFolderStatistics -FolderScope calendar | sort-object Name |ft Identity,Name

Well there are two too many. With the following command you only get the calendar, with all the extra info.

Get-MailboxFolderStatistics -identity [email protected] -FolderScope Calendar | Where-Object {$_.foldertype -eq "Calendar"}

In the extra info I also find the Identity. It looks like:

Identity                          :[email protected]\Agenda

Which is great of course. With this we can make the string for Set-MailboxFolderPermission.

It is difficult to follow, but the following command creates the string correctly.

$result = (Get-MailboxFolderStatistics -identity [email protected] -FolderScope Calendar | Where-Object {$_.foldertype -eq "Calendar"}).identity

$calendar = $result.insert($result.IndexOf('\'), ':')

I will not go into this too deeply. You can now use what is in string $Calendar for Set-MailboxFolderPermission.

With the following command we change the default AccessRights to LimitedDetails on the calendar of [email protected]:\agenda.

Set-MailboxFolderPermission -Identity $Calendar -User default -AccessRights LimitedDetails -ErrorAction SilentlyContinue

We did this for one Mailbox, in the next paragraph I’ll explain how to do this for multiple mailboxes.


Add-MailboxFolderPermissions -Identity MAILBOX:\Calendar for all users.

I am not going through all the steps again. The following script adjusts the Calendar Permissions for all mailboxes in Exchange Online. You can adjust the $AccessRights to what you want. The full list is here.

$Accessrights = "LimitedDetails"

Foreach ($mbx in (Get-Mailbox -ResultSize Unlimited))
{
    $Result = ((Get-MailboxFolderStatistics -identity $mbx.PrimarySmtpAddress -FolderScope Calendar | Where-Object {$_.foldertype -eq "Calendar"}).identity)
    $calendar = $result.insert($result.IndexOf('\'), ':')
    Add-mailboxfolderPermission -identity $Calendar -User Default -AccessRights $Accessrights -ErrorAction SilentlyContinue
}

In my case I had to Set the Mailbox Folder Permissions for a specific Security Group.

I had to do the following for a customer, they wanted the secretaries to have access to all employee calendars. The secretaries and employees are both in their own group.

I solved this by running a daily script that sets the permissions on the mailbox.
Because they’re added as a group you won’t adjust the existing permissions.

Do you have questions about the script below? Let me know.

$Secretaresses = "GrpSecrAgenda”
$Medewerkers = "GrpPilotAgenda”
$Accessrights = "LimitedDetails"

Foreach ($mbx in (Get-DistributionGroupMember -identity $Medewerkers))

{
    $Result = ((Get-MailboxFolderStatistics -identity $mbx.PrimarySmtpAddress -FolderScope Calendar | Where-Object {$_.foldertype -eq "Calendar"}).identity)

    $calendar = $result.insert($result.IndexOf('\'), ':')

    $calendar

    Add-mailboxfolderPermission -identity $Calendar -User $secretaresses -AccessRights $Accessrights -ErrorAction SilentlyContinue
}

What’s the difference between Add-MailboxFolderPermission and Set-MailboxFolderPermission?

With Add-MailboxFolderPermission you add the permissions to the mailbox.

If the permissions already exist and you want to change the -AccessRights then you use Set-MailboxFolderPermission.


A little extra

This post contains PowerShell. Would you like to learn the basics better? I have created a new website to learn basic PowerShell in an ’emulator’ environment.
Click here to go learn Basic PowerShell.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a PowerShell DevOps Engineer. In my spare time I write about interesting stuff that I encounter during my work.

One thought on “Get default calendar name for Mailbox Folder Permisssions Exchange PowerShell”

  1. nice and very helpful, thank you.
    Please note, you may need to convert the $result to a string to be able to add the “:”:

    $calendar = $result.toString().insert($result.toString().IndexOf(‘\’), ‘:’)

Leave a Reply

Your email address will not be published. Required fields are marked *