This article specifically address a problem I found when trying to disable archiving on specific folders in Exchange by following Prevent Notes, Calendar and Tasks from getting archived by using EWS script. When running the script I would get the error The UserId in the folder permission at index [xx] is invalid. The rest of this article will assume you have read the linked post and understand it.

The Cause

The script works by downloading the settings of a user’s calendar and adding a “no archive” personal tag to it, it then syncs these changes back to the online version of the folder. Where the problems starts is with the download of the folder; it doesn’t just download the folder name, it downloads delegate permissions as well. In my case it wasn’t downloading these permissions correctly so I had some blank entries (more on that later). After adding the archive tag it then tries to save the folder settings including the blank permissions resulting in the above error.

The fix

The above script downloads the user’s calendar by calling the bind method on line 50.

The default bind command downloads permissions as well. All we need to do is exclude them from the bind request. To do this we need to define a new property set which doesn’t include the permissions and then tell the bind to use this property set instead of the default property set. The below image shows the changes to the script to accommodate for this.

You need to add one line above the bind request to create the property set then tag that property set on the end of the bind request. This will fix the issue for you.

Print Friendly, PDF & Email