PowerShell: Set Calendar folder delegate permissions in Exchange 2007


Exchange 2010 has cmdlets (Add-MailboxFolderPermission, Set-MailboxFolderPermission) that allow an administrator to update folder permissions on a user’s calendar.  Unfortunately, Exchange 2007 does not have these cmdlets.  We recently had a case that required updating many mailboxes (in this case resource mailboxes) to allow all users to be able to see the calendar (and details of bookings) in those mailboxes.  Attached is a PowerShell script that uses EWS to update calendar permissions accordingly (including Default and Anonymous permissions).  The script works in later versions of Exchange, though built in cmdlets from Exchange 2010 and above can do the same task.  The mailbox parameter of the script can specify a CSV file instead of a mailbox, in which case all mailboxes contained in the CSV file will be processed.

Syntax:

Set-CalendarFolderPermission -Mailbox <string>
                  -Delegate <string>
                  -Permission <string>
                   [-AuthUsername <string> -AuthPassword <string> [-AuthDomain <string>]]
                   [-Impersonate <bool>]
                   [-EwsUrl <string>]
                   [-EWSManagedApiPath <string>]
                   [-IgnoreSSLCertificate <bool>]
                   [-WhatIf <bool>]

Required:
 -Mailbox : Mailbox SMTP email address, OR CSV file containing list of mailboxes to process
 -Delegate : Email address of the user who is being given the permissions (or can use Default or Anonymous)
 -Permission : None, Owner, PublishingEditor, Editor, PublishingEditor, Author, NoneditingAuthor, Reviewer, Contributor, FreeBusyTimeOnly, FreeBusyTimeAndSubjectAndLocation

Optional:
 -AuthUsername : Username for the account being used to connect to EWS (if not specified, current user is assumed)
 -AuthPassword : Password for the specified user (required if username specified)
 -AuthDomain : If specified, used for authentication (not required even if username specified)
 -Impersonate : Set to $true to use impersonation.
 -EwsUrl : Forces a particular EWS URl (otherwise autodiscover is used, which is recommended)
 -EWSManagedApiDLLFilePath : Full and path to the DLL for EWS Managed API (if not specified, default path for v1.2 is used)
 -IgnoreSSLCertificate : If $true, then any SSL errors will be ignored
 -WhatIf : If $true, then no changes are saved

 

Set-CalendarFolderPermission.ps1

Comments (4)

  1. Sorted out that it's need to run in PS 2.0. But still error.

    Exception calling "Update" with "0" argument(s): "Access is denied. Check credentials and try again."

    At C:SupportSet-CalendarFolderPermission.ps1:154 char:4

    +             $Folder.Update()

    +             ~~~~~~~~~~~~~~~~

       + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

       + FullyQualifiedErrorId : ServiceResponseException

  2. Babu says:

    Please share the example command using the above script…

  3. Andy says:

    Hi, thanks for this script. Is it possible to tell me what changes to make if I'm using Exchange 2007 SP3 and ESW 2.0?

    I've used the -EWSUrl parameter to point to my EWS v2.0 folder but am getting errors when running the script. I'm not sure if it's service pack specific?

    Processing mailbox: andy.surname

    Exception calling "Bind" with "3" argument(s): "The request failed. The underlying connection was closed: An unexpected error occurred on a send."

    At Set-CalendarFolderPermission.ps1:92 char:62

    +     $Folder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind <<<< ($service, $FolderId, $PropertySet)

       + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

       + FullyQualifiedErrorId : DotNetMethodException

    You cannot call a method on a null-valued expression.

    At Set-CalendarFolderPermission.ps1:143 char:27

    +             $Folder.Permissions.Add <<<< ( $newPermission )

       + CategoryInfo          : InvalidOperation: (Add:String) [], RuntimeException

       + FullyQualifiedErrorId : InvokeMethodOnNull

    Permission for duane.dibbley added

    Applying changes

    You cannot call a method on a null-valued expression.

    At Set-CalendarFolderPermission.ps1:154 char:18

    +             $Folder.Update <<<< ()

       + CategoryInfo          : InvalidOperation: (Update:String) [], RuntimeException

       + FullyQualifiedErrorId : InvokeMethodOnNull

  4. Dan Voller says:

    We've got exactly the same error as Andy does "Bind" with "3" argument(s): "The request failed. The underlying connection was closed: An unexpected error occurred on a send."

    We're using Exchange 2007, SP3.

    David, can you please help us with that, thanks a lot!

    Dan