{"id":131,"date":"2015-03-19T08:38:36","date_gmt":"2015-03-19T12:38:36","guid":{"rendered":"https:\/\/www.ccrossan.com\/?p=131"},"modified":"2016-07-07T08:03:59","modified_gmt":"2016-07-07T12:03:59","slug":"pushing-calendar-events-with-the-ews-api","status":"publish","type":"post","link":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/","title":{"rendered":"Pushing Calendar Events with the EWS API"},"content":{"rendered":"\n<div class=\"twitter-share\"><a href=\"https:\/\/twitter.com\/intent\/tweet?via=crossan007\" class=\"twitter-share-button\">Tweet<\/a><\/div>\n<p>We&#8217;ve had\u00a0a need to populate users&#8217; calendars with data from\u00a0an internal FileMaker Database, so I dug around in the EWS API, and came up with a script that uses the FileMaker ODBC Connection, and the EWS API to accomplish the task:<\/p>\n<p>First things first, we need to install the<a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=42951\"> EWS Managed API<\/a> on the machine that will run the script.<\/p>\n<p>After the EWS Managed API is installed, we need to reference it in our PowerShell script:<\/p>\n<blockquote><p>Add-Type -Path &#8220;C:\\Program Files\\Microsoft\\Exchange\\Web Services\\2.2\\Microsoft.Exchange.WebServices.dll&#8221;<\/p><\/blockquote>\n<p>Next, we need to set up a System.Net.NetworkCredential object for the account we&#8217;ll use to push these events. \u00a0This account must have at least modify permission on the target users&#8217; calendar.<\/p>\n<blockquote><p>$Credentials = new-object system.net.NetworkCredential(&#8220;CalendarAccessAccount&#8221;,&#8221;SuperStrongPa$$w0Rd!&#8221;,&#8221;litware&#8221;)<\/p><\/blockquote>\n<p>Next, we need to Create anMicrosoft.Exchange.WebServices.Data.ExchangeService object:<\/p>\n<blockquote><p>$version = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1<br \/>\n$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService($version)<\/p><\/blockquote>\n<p>We don&#8217;t want to use the default credentials, Instead we want to authenticate using the service account specified earlier:<\/p>\n<blockquote><p>$service.UseDefaultCredentials = $false<br \/>\n$service.Credentials=$Credentials<\/p><\/blockquote>\n<p>And, presuming AutoDiscover is set up correctly in our domain, we want to let EWS figure out the server address, port, etc:<\/p>\n<blockquote><p>$service.AutodiscoverUrl(&#8220;TargetMailbox@litware.com&#8221;)<\/p><\/blockquote>\n<p>Next, we need to reference the user&#8217;s calendar (it&#8217;s really just a folder as far as the API is concerned):<\/p>\n<blockquote><p>$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar, &#8220;TargetMailbox@litware.com&#8221;)<\/p><\/blockquote>\n<p>And finally, we build the appointment object:<\/p>\n<blockquote><p>$Appointment = New-Object Microsoft.Exchange.WebServices.Data.Appointment -ArgumentList $Service<br \/>\n$appointment.Subject = &#8220;Test111&#8221;<br \/>\n$appointment.Body = &#8220;Test111&#8221;<br \/>\n$appointment.Start = $(Get-Date).AddHours(6)<br \/>\n$appointment.End =$(Get-Date).AddHours(9)<\/p><\/blockquote>\n<p>Don&#8217;t forget to save it:<\/p>\n<blockquote><p>$appointment.Save($folderid)<\/p>\n<p>&nbsp;<\/p><\/blockquote>\n<p>All in all, we can wrap this up as a function:<\/p>\n<blockquote><p>Function CreateAppointment($User,$Credentials)<br \/>\n{<br \/>\n$mailboxName=$User<br \/>\n$version = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1<br \/>\n$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService($version)<br \/>\n$service.UseDefaultCredentials = $false<br \/>\n$service.Credentials=$Credentials<br \/>\n$service.AutodiscoverUrl($mailboxName)<\/p>\n<p>$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar, $mailboxName)<\/p>\n<p>$Appointment = New-Object Microsoft.Exchange.WebServices.Data.Appointment -ArgumentList $Service<br \/>\n$appointment.Subject = &#8220;Test\u00a0Subject&#8221;<br \/>\n$appointment.Body = &#8220;Test Body&#8221;<br \/>\n$appointment.Start = $(Get-Date).AddHours(6)<br \/>\n$appointment.End =$(Get-Date).AddHours(9)<\/p>\n<p>$appointment.Save($folderid)<\/p>\n<p>}<\/p><\/blockquote>\n<p>Now we can call the function from, say, with a loop so as to iterate through each user in a CSV:<\/p>\n<blockquote><p>$users = Import-CSV &#8220;Users.csv&#8221;<\/p>\n<p>$Credentials = new-object system.net.NetworkCredential(&#8220;CalendarAccessAccount&#8221;,&#8221;SuperStrongPa$$w0Rd!&#8221;,&#8221;litware&#8221;)<\/p>\n<p>Foreach ($User in $Users)<\/p>\n<p>{<\/p>\n<p>CreateAppointment $User $Credentials<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p><\/blockquote>\n<p>More to come later on the FileMaker ODBC Connection&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve had\u00a0a need to populate users&#8217; calendars with data from\u00a0an internal FileMaker Database, so I dug around in the EWS API, and came up with a script that uses the FileMaker ODBC Connection, and the EWS API to accomplish the task: First things first, we need to install the EWS Managed API on the machine &hellip; <a href=\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Pushing Calendar Events with the EWS API<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28],"tags":[176,30,47,29],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pushing Calendar Events with the EWS API - Charles&#039; Blog\" \/>\n<meta property=\"og:description\" content=\"We&#8217;ve had\u00a0a need to populate users&#8217; calendars with data from\u00a0an internal FileMaker Database, so I dug around in the EWS API, and came up with a script that uses the FileMaker ODBC Connection, and the EWS API to accomplish the task: First things first, we need to install the EWS Managed API on the machine &hellip; Continue reading Pushing Calendar Events with the EWS API &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Charles&#039; Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-03-19T12:38:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-07-07T12:03:59+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"crossan007\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/crossan007.dev\/blog\/#website\",\"url\":\"https:\/\/crossan007.dev\/blog\/\",\"name\":\"Charles&#039; Blog\",\"description\":\"SharePoint | PowerShell | Exchange | SCCM | Ubuntu | PHP | JavaScript | A\/V Live Production | More...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/crossan007.dev\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/#webpage\",\"url\":\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/\",\"name\":\"Pushing Calendar Events with the EWS API - Charles&#039; Blog\",\"isPartOf\":{\"@id\":\"https:\/\/crossan007.dev\/blog\/#website\"},\"datePublished\":\"2015-03-19T12:38:36+00:00\",\"dateModified\":\"2016-07-07T12:03:59+00:00\",\"author\":{\"@id\":\"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979\"},\"breadcrumb\":{\"@id\":\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/crossan007.dev\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pushing Calendar Events with the EWS API\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979\",\"name\":\"crossan007\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/crossan007.dev\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g\",\"caption\":\"crossan007\"},\"url\":\"https:\/\/crossan007.dev\/blog\/author\/crossan007\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/","og_locale":"en_US","og_type":"article","og_title":"Pushing Calendar Events with the EWS API - Charles&#039; Blog","og_description":"We&#8217;ve had\u00a0a need to populate users&#8217; calendars with data from\u00a0an internal FileMaker Database, so I dug around in the EWS API, and came up with a script that uses the FileMaker ODBC Connection, and the EWS API to accomplish the task: First things first, we need to install the EWS Managed API on the machine &hellip; Continue reading Pushing Calendar Events with the EWS API &rarr;","og_url":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/","og_site_name":"Charles&#039; Blog","article_published_time":"2015-03-19T12:38:36+00:00","article_modified_time":"2016-07-07T12:03:59+00:00","twitter_misc":{"Written by":"crossan007","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/crossan007.dev\/blog\/#website","url":"https:\/\/crossan007.dev\/blog\/","name":"Charles&#039; Blog","description":"SharePoint | PowerShell | Exchange | SCCM | Ubuntu | PHP | JavaScript | A\/V Live Production | More...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/crossan007.dev\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/#webpage","url":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/","name":"Pushing Calendar Events with the EWS API - Charles&#039; Blog","isPartOf":{"@id":"https:\/\/crossan007.dev\/blog\/#website"},"datePublished":"2015-03-19T12:38:36+00:00","dateModified":"2016-07-07T12:03:59+00:00","author":{"@id":"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979"},"breadcrumb":{"@id":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/crossan007.dev\/blog\/microsoft-exchange\/pushing-calendar-events-with-the-ews-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/crossan007.dev\/blog\/"},{"@type":"ListItem","position":2,"name":"Pushing Calendar Events with the EWS API"}]},{"@type":"Person","@id":"https:\/\/crossan007.dev\/blog\/#\/schema\/person\/bd99569cd81332c8fd866d023848b979","name":"crossan007","image":{"@type":"ImageObject","@id":"https:\/\/crossan007.dev\/blog\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fff72c74fb6a0da29accf0db83ad4b4b?s=96&d=mm&r=g","caption":"crossan007"},"url":"https:\/\/crossan007.dev\/blog\/author\/crossan007\/"}]}},"_links":{"self":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts\/131"}],"collection":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/comments?post=131"}],"version-history":[{"count":2,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":133,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/posts\/131\/revisions\/133"}],"wp:attachment":[{"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/media?parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/categories?post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crossan007.dev\/blog\/wp-json\/wp\/v2\/tags?post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}