PowerShell: Script to import calendar items into Exchange mailbox from CSV file

A recent case brought up the question of whether it is possible to import calendar items into a mailbox from a text file using PowerShell.  While there aren't any cmdlets built-in that support this, it is certainly possible to implement this using PowerShell and the EWS Managed API.  Sample script is attached, and the syntax is:


Import-CalendarCSV -CSVFileName <string> -EmailAddress <string> [-Username <string> -Password <string> [-Domain <string>]] [-Impersonate <bool>] [-EwsUrl <string>] [-EWSManagedApiPath <string>]



Filename of the CSV file to import appointments for this user from.

Mailbox SMTP email address


Username for the account being used to connect to EWS (if not specified, current user is assumed)

Password for the specified user (required if username specified)

If specified, used for authentication (not required even if username specified)

Set to $true to use impersonation.

Forces a particular EWS URl (otherwise autodiscover is used, which is recommended)

Full and path to the DLL for EWS Managed API (if not specified, default path for v1.1 is used)


To process the CSV file c:\calendar.csv and import all entries into the mailbox of user@domain.com, you would use the following command:

Import-CalendarCSV -CSVFileName c:\calendar.csv -EmailAddress user@domain.com

The CSV needs to be in the format Subject, Start Date, Start Time, End Date, End Time.

Other fields can be added, and if this is the case you will need to add a header row to the CSV file.  The headers need to include the five required fields (Subject, Start Date, Start Time, End Date, End Time) and any other fields you like.  You should be able to use any of the fields listed here as additional fields, so long as they are simple (i.e. just contain a single value); this means that you can't specify Attachments, for example.


Comments (6)

  1. Ben says:


    This script would be very handy.  When we run it, we get the following error:

    "Exception calling "AutodiscoverUrl" with "1" argument(s): "Autodiscover blocked a potentially insecure redirection to autodiscover-s.outlook.com/…/autodiscover.xml. To allow Autodiscover to follow the redirection, use the AutodiscoverUrl(string, AutodiscoverRedirectionUrlValidationCallback) overload."

    If I add the EWS URL as a switch, using outlook.office365.com/…/exchange.asmx I get the following error:

    "Exception calling "Bind" with "2" argument(s): "The request failed. The remote server returned an error: (401)


    I have tested using EWS Editor, and Auto DIscover works.  Can you point me in the right direction?



  2. bluefiore says:

    I'm getting this error 5 times, I gues for every value in csv test file.

    Unable to index into an object of type System.Management.Automation.PSObject.

    At C:tmpImport-CalendarCSV.ps1:72 char:16

    +     if (!$CSVFile[ <<<< 0].$Key)

       + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException

       + FullyQualifiedErrorId : CannotIndex

    When i do Import-Csv it reads values just fine.

    At the end of script I get "Created" & subject, but no entry in calendar. Any suggestions? Thanks in advanced.

  3. Georg says:


    could this method work with a public folder as target?

    I tried but i get an error with autodiscover,

    Exception with autodiscoverUrl

    CategoryInfo: not specified

    FQErrorID: DotnetMethodException

  4. Hussain says:


    This is an excellent idea to implement it to group of students. Will it be possible to target member Mailbox of  Distribution Group?

    What about looping through multiple entries in a CSV file for 400 students?


  5. ab says:


    Is there anyway to import it to a non-default calendar ?

    thank you

  6. Engin says:


    First of all your script really helped me to automate some tasks thank you very much!

    I just want to assign/add Categories as well for all the appointments and tried many things but it’s failing to find the correct context. I’ve added this line below to your script but did not help either. Is there anybody to tell me this correct field name for a Category? It should be Categories according to reference sheet but not working somehow.



Skip to main content