Meeting cancellation script updated for large result sets

Articles in the "Meeting cancellation script" series

  1. Cancel future meetings in a mailbox
  2. Meeting cancellation script updated
  3. Meeting cancellation script updated for large result sets [This article]

The default for the script is to get all appointment items for the next year.  This includes all occurrences of recurring appointments.  For the really busy person, or if you specify the end date beyond a year, that could mean more than the maximum of 1000 items.  To accommodate more than the search result maximum, you would normally use paging.  A calendar view, however, does not support paging (even though the search result has a property to indicate there are more items than what were returned).  To work around this I added pseudo-paging that performs successive loops with a start date that is set to the start of the last appointment in the previous search result.  This causes duplicate items in the collection of appointments, though, so I added a step to filter these.  These changes are transparent, so you don’t need to do anything to accommodate mailboxes that have more than 1000 appointments.

Another change is the addition of the AttendeeMeetingsOnly parameter.  This switch causes the script to only process meetings where the mailbox is an attendee.  Parameter sets have been defined so you cannot use this parameter at the same time as IncludeAttendeeMeetings.  This now means the options are to process meetings where the mailbox is the organizer (the default), to additionally process meetings where the mailbox is an attendee (use IncludeAttendeeMeetings), or to process only the latter (use AttendeeMeetingsOnly).

I changed the way the script identifies recurring meetings because of an issue that sometimes occurs, causing the IsRecurring property to incorrectly have a value of True on a single-instance meeting.  And, lastly, already canceled meetings are now excluded.  (An attendee mailbox that has received a meeting cancellation, but has not been “accepted” by the user, is already in a cancelled state in the mailbox and cannot be declined.)  Thank you to Zafer for identifying bugs recently so they can be fixed.

Here is the updated script:

  Cancel-MailboxMeetings.ps1 (12.7 KiB)

2 thoughts on “Meeting cancellation script updated for large result sets

  1. We have requirement when a meeting room closed the room should decline/cancel all meetings and meeting template should originate from the meeting room itself to cancel/decline the meetings for the users from the meeting room.

    I am getting the below error when I declare the UserID

     

     

    Exception calling “Bind” with “2” argument(s): “The request failed. The remote server returned an error: (401)
    Unauthorized.”
    At line:253 char:2
    + $calFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ServiceRequestException

    Exception calling “FindAppointments” with “2” argument(s): “The element at position 0 is invalid
    Parameter name: parentFolderIds”
    At line:274 char:3
    + $searchResult = $exchangeService.FindAppointments($calFolder. …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException

    Exception calling “AddRange” with “1” argument(s): “Value cannot be null.
    Parameter name: collection”
    At line:286 char:3
    + $appointments.AddRange($searchResult.Items)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException

    There are no meetings in the specified timeframe.

  2. The 401 indicates that the calling account does not have permission to the mailbox. Does the account that is being used with implicit credentials or the account being used with explicit credentials (and assuming the provided credentials are correct) have full mailbox access to the conference room? Or if impersonation is being used, does the calling account have the ApplicationImpersonation role assigned? (If the credentials are correct and impersonation is being used, I think the error would be different, actually saying the account does not have impersonation rights to the mailbox, but I don’t recall if it is in a 401 response.)

Leave a Reply

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

*