PowerShell: Search for appointments 5/5 (1)

You can use the Exchange cmdlet Search-Mailbox for a wide variety of searches, but it does have some limitations.  Attached here is a PowerShell script that uses EWS to search appointments, and as the script uses both server and client side search it can be used to performs searches that aren’t possible with Search-Mailbox (and it can also be used on your own mailbox without requiring to connect to an Exchange PowerShell session).  This script will work for both on-premise installations of Exchange (2010 or higher, it will probably work with 2007 but may need minor changes, and I haven’t tested there!) as well as Office 365.

The download link for this script has been removed, as it has now been moved to: https://gallery.technet.microsoft.com/Search-Mailbox-for-c9279266


 -Mailbox The mailbox to be processed (if missing, current user’s mailbox is assumed, though this will only work in a domain environment).
 -FolderPath  Folder to search – if omitted, the mailbox calendar folder is assumed.
 -PublicFolders  If this switch is present, folder path is required and the path points to a public folder.
 -Subject  Subject of the appointment(s) being searched.  A -like comparison is used, so wildcards should work.
 -StartsAfter  Start date for the appointment(s) must be after this date.
 -StartsBefore  Start date for the appointment(s) must be before this date.
 -EndsBefore  End date of the appointment(s) must be before this date.
 -EndsAfter  End date of the appointment(s) must be after this date.
 -CreatedBefore  Only appointments created before the given date will be returned.
 -CreatedAfter  Only appointments created after the given date will be returned.
 -LastOccurrenceBefore  Only recurring appointments with a last occurrence date before the given date will be returned.
 -LastOccurrenceAfter  Only recurring appointments with a last occurrence date after the given date will be returned.
 -IsRecurring  If this switch is present, only recurring appointments are returned (note that this is implied if LastOccurrenceBefore or LastOccurrenceAfter are set).
 -Delete  If specified, any matched appointments will be deleted. Use with care!
 -Credentials  Credentials used to authenticate with EWS.
 -Username  Username used to authenticate with EWS.
 -Password  Password used to authenticate with EWS.
 -Domain  Domain used to authenticate with EWS.
 -Impersonate  Whether we are using impersonation to access the mailbox.
 -EwsUrl  EWS Url (if omitted, then autodiscover is used).
 -EwsManagedApiPath  Path to managed API (if omitted, a search of standard paths is performed).
 -IgnoreSSLCertificate  Whether to ignore any SSL errors (e.g. invalid certificate) – use with care.
 -AllowInsecureRedirection  Whether to allow insecure redirects when performing autodiscover.
 -LogFile  Log file – activity is logged to this file if specified.
 -ExportCSV  File to which matching appointment data will be exported


.\Search-Appointments.ps1 -LastOccurrenceAfter 30/Dec/2016 -ExportCSV c:\temp\apts.csv
Will find all appointments in the current user’s calendar with a last occurrence date after 30th December 2016 (note that this will only match recurring appointments)

.\Search-Appointments.ps1 -Mailbox user@office365.com -Credentials (Get-Credential) -LastOccurrenceAfter 30/Dec/2016 -ExportCSV c:\temp\apts.csv
Performs the same search as the first example, but against an Office 365 mailbox and will prompt for credentials.

.\Search-Appointments.ps1 -LastOccurrenceAfter 30/Dec/2016 -ExportCSV c:\temp\apts.csv -Delete
Performs the same search as the first example, but deletes any matching appointments found (the details of those appointments will also be exported to the CSV).

Please rate this


13 thoughts on “PowerShell: Search for appointments

  1. Hello,

    i want to thank you for this amazing script.
    And i want to ask is it possible for this to modified so it can be possible to search again in entire org and meetings from particular mbx ?
    the goal it to search of all meetings (hr inbox) send across the organisation.

    Thank you very much in advance.

  2. It’s a great script, the best i found. Only 1 thing which seems not be working. When i choose the option to delete calendar items it doesn’t notify the Attendees or the Organizer.
    Also not after having changed the SendCancellationsMode to the below.

    Any idea why?

  3. Great script! We are undergoing a massive reorganization (Covid related) and i’m looping through all roommailboxes.
    One thing doesn’t seem to work, when i delete meetings and want to send cancellation notification emails those emails are not send (user has booked these meetings properly from within his own calendar). I changed already the SendCancellationsMode to what it needs to be but no luck… 🙁

    [void]$script:service.DeleteItems( $deleteIds, [Microsoft.Exchange.WebServices.Data.DeleteMode]::MoveToDeletedItems,[Microsoft.Exchange.WebServices.Data.SendCancellationsMode]::SendToAllAndSaveCopy, $Null )

    Any idea?

    1. I’ve just checked, and that should be the only change needed. Have you updated the SendCancellationsMode in both places of the script? There are two calls that need to be updated (line 1221 and 1229). I’ll make a note to add this as a parameter for the next version of the script.

  4. I am not sure how often this post is being reviewed but, I would seriously love to use this for a project I am working on. Currently, I am getting the following error:

    PS C:\ews> . c:\EWS\search-appointments.ps1 -Mailbox john.doe@nonprofit.org -Subject “Christmas Day”
    search-appointments.ps1 version 1.1.2 starting
    Using EWS Managed API found at: C:\ews\Microsoft.Exchange.WebServices.dll
    Processing mailbox john.doe@nonprofit.org
    john.doe@nonprofit.org : error occurred during autodiscover: Exception calling “AutodiscoverUrl” with “1” argument(s): “Autodiscover blocked a potentially insecure redirection to https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml. To allow Autodiscover to follow the redirection, use the AutodiscoverUrl(string, AutodiscoverRedirectionUrlValidationCallback) overload.”
    Failed to create ExchangeService
    Exception calling “Bind” with “2” argument(s): “Object reference not set to an instance of an object.”
    At C:\EWS\search-appointments.ps1:1265 char:10
    + $Folder = [Microsoft.Exchange.WebServices.Data.Folder]::B …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

    You cannot call a method on a null-valued expression.
    At C:\EWS\search-appointments.ps1:1034 char:13
    + $results = $Folder.FindItems($view)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    I have attempted for 10 days now to resolve the issue and unfortunately, I have been unsuccessful. Can you please give some guidance as to what can be done to resolve this error.

  5. I have been asked to add the EmailMessageSchema of the ToRecipients; CcRecipients; and BccRecipients, I was adding around line 879, but it is not exporting the data. what have I missed?

    1. figured out except the way to display the BCC, DeiplayTo and DisplayCC in the EmailMessageSchema is the closest I got. I also had modified the ProcessItem function to print – I did not mention that before.

  6. We are getting duplicate appointments when we fetch the data.some appointments are not part of outlook calender.why is this happening when we are trying to fetch by start and end time

    1. The script cannot pull back appointments that aren’t there, so what you are seeing must have come from the mailbox. It would be impossible for me to comment without seeing a trace, though.


Leave a Reply

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