Changing default Exchange Calendar permissions

A customer recently asked me to reset the default Calendar rights for all the users in the company. As I quickly agreed and claimed this would be a one-liner in Powershell I remembered that the Calendar rights on this server (Exchange 2010) were as a matter of fact quite hidden.

Also, this customer had multiple regional settings in his environment; this blows most of the filtering options out of the water.

So, off to script a function-  which payed of in the end. The customer had to back-track on his decision.

The function I wrote

A small and easy function that accepts a list of mailboxes as input, and a validated set of options for the access rights from the Microsoft site. At this moment I’ve only added AvailabilityOnly and LimitedDetails as options – but you can always update them.

The function uses Exchange cmdlets, so we’ll need the Exchange modules loaded and an active connection to Exchange.

function Set-DefaultCalendarRights {
    param (
        [string[]]$Mailboxes,
        [ValidateSet("AvailabilityOnly","LimitedDetails")][string]$AccessRights
    )

    Foreach ($Mailbox in $Mailboxes) {
        $CalendarFolder = Get-MailboxFolderStatistics $Mailbox | Where-Object {$_.FolderType -eq "Calendar"}
        if ($CalendarFolder) {
        $Folder = $mailbox.alias + ":" + $CalendarFolder.Name
        Set-MailboxFolderPermission -Identity $Folder  -User default -AccessRights AvailabilityOnly # -Whatif
        }
    }
}

# Example: load a set of mailboxes and set the access rights.

$Mailboxes = get-mailbox -OrganizationalUnit "OU=Users,DC=jaaplab,DC=nl"

Set-DefaultCalendarRights -Mailboxes $Mailboxes -AccessRights LimitedDetails

Some context on the script. There is no error handling whatsoever – so make sure you know what you are doing.  The script tries to retrieve all the mailbox names you put into it, and retrieves a list of folders in the mailbox.

Instead of focusing on the name of the folder I had to switch to the FolderType because of regional settings (us Dutchies call the Calendar an Agenda).

When the script finds a folder it will construct a name accepted by the Set-MailboxFolderPermission cmdlet and try to reset the folder to the permissions passed to it. If you’re a bit squimish like I can be, you can remove the comment before the what-if and first try to see what it does.