Set Calendar Permission in Office 365 Exchange Online
Introduction
This script can set calendar permission in Office 365 Exchange Online. You can set permission, grant permission and revoke permission on one or multiple calendar folders by using this script.
Scenarios
Currently, Add-MailboxFolderPermission only accepts single ID as the value of Identity parameter. It requires user to provide a full folder path, for example, "userid\Calendar\Calendar 01". It's inconvenient if you want to set permission on two or more
calendar folders.
Prerequisites
This script requires Exchange Web Service Managed API 2.0. Please download and install the package from
Microsoft Download Center. This script cannot work correctly without this package.
Script
This script contains the following advanced functions:
- Connect-OSCEXOWebService
- Get-OSCEXOCalendarFolder
- Grant-OSCEXOCalendarFolderPermission
- Revoke-OSCEXOCalendarFolderPermission
- Set-OSCEXOCalendarFolderPermission
You can use this script in the following way.
- Open Windows PowerShell.
- Run Import-Module cmdlet to import this module file.
Import-Module filepath\scriptname.psm1
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
PowerShell
Edit|Remove
powershell
Try
{
$result = $Folder.Permissions.Add($newPermission)
$Folder.Update()
if ($result) {
$verboseMsg = $Messages.SucceededToAddPermision
$verboseMsg = $verboseMsg -f $userSmtpAddress,$PermissionLevel
$PSCmdlet.WriteVerbose($verboseMsg)
} else {
$verboseMsg = $Messages.FailedToAddPermision
$verboseMsg = $verboseMsg -f $userSmtpAddress,$PermissionLevel
$PSCmdlet.WriteVerbose($verboseMsg)
}
}
Catch
{
$PSCmdlet.WriteError($_)
}
Try
{
$result = $Folder.Permissions.Add($newPermission)
$Folder.Update()
if ($result) {
$verboseMsg = $Messages.SucceededToAddPermision
$verboseMsg = $verboseMsg-f $userSmtpAddress,$PermissionLevel$PSCmdlet.WriteVerbose($verboseMsg)
} else {
$verboseMsg = $Messages.FailedToAddPermision
$verboseMsg = $verboseMsg-f $userSmtpAddress,$PermissionLevel$PSCmdlet.WriteVerbose($verboseMsg)
}
}
Catch
{
$PSCmdlet.WriteError($_)
}
Examples
Example 1: How to display help about
Set-OSCEXOCalendarFolderPermission.
To display help about this function, please run this command.
Get-Help Set-OSCEXOCalendarFolderPermission -Full
Example 2: How to initiate a connection to Office 365 Exchange Online.
To initiate a connection to Office 365 Exchange Online, please run this command. You must run this example before any other step.
Connect-OSCEXOWebService -Credential (Get-Credential
admin@domain01.onmicrosoft.com)
Note The Connect-OSCEXOWebService function creates a new variable called exService. This variable is in the global scope of the current Windows PowerShell session. This variable is used by other functions in the script.
Example 3: How to get a calendar folder that contains a specified string as the DisplayName property.
To get a calendar folder that contains a specified string as the DisplayName property, please run this command.
Get-OSCEXOCalendarFolder -DisplayName "2012" -ExactMatch -FolderTraversal Shallow
Example 4: How to grant contributor permission to John Doe (johnd) to access a calendar folder.
To grant contributor permission to John Doe (johnd) to access a calendar folder, please run this command.
Get-OSCEXOCalendarFolder -DisplayName "2012" -ExactMatch -FolderTraversal Shallow | Grant-OSCEXOCalendarFolderPermission -UserName johnd -PermissionLevel Contributor -Verbose
Note You should use Set-OSCEXOCalendarFolderPermission to update the permission for an existing user.
Example 5: How to grant contributor permission to John Doe (johnd) to access a calendar folder and its sub folders.
To grant contributor permission to John Doe (johnd) to access multiple calendar folders and its sub folders, please run this command.
Get-OSCEXOCalendarFolder -Path "\2012\" | %{Grant-OSCEXOCalendarFolderPermission -Folder $_ -UserName johnd -PermissionLevel Contributor -Verbose}

Example 6: How to revoke contributor permission on a calendar folder from John Doe (johnd).
To revoke contributor permission on a calendar folder from John Doe (johnd), please run this command.
Get-OSCEXOCalendarFolder -DisplayName "2012" -ExactMatch -FolderTraversal Shallow | Revoke-OSCEXOCalendarFolderPermission -UserName johnd -PermissionLevel Contributor -Verbose

Example 7: How to revoke contributor permission on a calendar folder and its sub folders from John Doe (johnd).
To revoke contributor permission on a calendar folder and its sub folders from John Doe (johnd), please run this command.
Get-OSCEXOCalendarFolder -Path "\2012\" | %{Revoke-OSCEXOCalendarFolderPermission -Folder $_ -UserName johnd -PermissionLevel Contributor -Verbose}
Example 8: How to set permission for John Doe (johnd) on a calendar folder.
To set permission for John Doe (johnd) on a calendar folder, please run this command.
Get-OSCEXOCalendarFolder -DisplayName "2012" -ExactMatch -FolderTraversal Shallow | Set-OSCEXOCalendarFolderPermission
-UserName johnd -PermissionLevel Editor -Verbose

Example 9: How to set permission for John Doe (johnd) on a calendar folder and its sub folders.
To set permission for John Doe (johnd) on a calendar folder and its sub folders, please run this command.
Get-OSCEXOCalendarFolder -Path "\2012\" | %{Set-OSCEXOCalendarFolderPermission -Folder $_ -UserName johnd -PermissionLevel Editor -Verbose}

Additional Resources