<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Developer Messaging</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/devmsg/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/devmsg/feed.xml</link>
    <description>Blog related to Exchange and Outlook Development technologies... So if you are looking for Exchange Web Serivces, Outlook Object Model, VSTO Addin development, CDO 1.21, WebDAV ..... then you are at right place.</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:50:04 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>EWS Script to automatically generate registry keys to enable Custom Forms in Outlook</title>
      <link>https://docs.microsoft.com/archive/blogs/devmsg/ews-script-to-automatically-generate-registry-keys-to-enable-custom-forms-in-outlook</link>
      <pubDate>Tue, 14 Nov 2017 21:08:05 GMT</pubDate>
      <dc:creator><![CDATA[Akashb]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devmsg/?p=85</guid>
      <description><![CDATA[&nbsp;

As you know Custom form script is now disabled by default and you will need to create a...]]></description>
      <content:encoded><![CDATA[&nbsp;

As you know Custom form script is now disabled by default and you will need to create a set of registry keys as outlined in <a href="https://support.office.com/en-us/article/Custom-form-script-is-now-disabled-by-default-bd8ea308-733f-4728-bfcc-d7cce0120e94">this</a> KB. We have had a few customers who have a lot of custom forms published in the Organizational Forms Library and it can be painful to get the message class of each of those form and then create the registry entries. The script below iterates through all the forms published in the Organizational Forms Library and then generates the required set of registry keys.

This is a PowerShell script that uses <a target="_blank" href="https://www.microsoft.com/en-us/download/details.aspx?id=42951" rel="noopener">EWS Managed API Ver 2.2</a> to access the Organizational Forms Library and generate the registry keys. This script will need to be run with credentials of a user that has access to the Organizational Forms Library.
<div id="codeSnippetWrapper" style="font-size: 8pt;overflow: auto;cursor: text;height: 1000px;font-family: 'Courier New', courier, monospace;width: 100%;direction: ltr;text-align: left;margin: 20px 0px 10px;line-height: 12pt;max-height: 2000px;background-color: #f4f4f4;border: silver 1px solid;padding: 4px">
<div id="codeSnippet" style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000">#</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"><span style="color: #008000"># DumpMessageClassforForms.ps1</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000">#</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"><span style="color: #008000"># By Akash Bhargava, Microsoft Ltd. 2017. Use at your own risk.  No warranties are given.</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000"># Thank you David for the Template</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"><span style="color: #008000"># DISCLAIMER:</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000"># THIS CODE IS SAMPLE CODE. THESE SAMPLES ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"><span style="color: #008000"># MICROSOFT FURTHER DISCLAIMS ALL IMPLIED WARRANTIES INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR OF FITNESS FOR</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000"># A PARTICULAR PURPOSE. THE ENTIRE RISK ARISING OUT OF THE USE OR PERFORMANCE OF THE SAMPLES REMAINS WITH YOU. IN NO EVENT SHALL</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"><span style="color: #008000"># MICROSOFT OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000"># BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THE</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"><span style="color: #008000"># SAMPLES, EVEN IF MICROSOFT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000"># OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE LIMITATION MAY NOT APPLY TO YOU.</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #0000ff">param</span> (</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    [Parameter(Mandatory=$False,HelpMessage=<span style="color: #006080">"Username used to authenticate with EWS"</span>)]</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    [string]$AuthUsername,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    [Parameter(Mandatory=$False,HelpMessage=<span style="color: #006080">"Password used to authenticate with EWS"</span>)]</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    [string]$AuthPassword,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    [Parameter(Mandatory=$False,HelpMessage=<span style="color: #006080">"Domain used to authenticate with EWS"</span>)]</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    [string]$AuthDomain,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    [Parameter(Mandatory=$False,HelpMessage=<span style="color: #006080">"EWS Url (if omitted, then autodiscover is used)"</span>)]</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    [string]$EwsUrl,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    [Parameter(Mandatory=$False,HelpMessage=<span style="color: #006080">"Path to managed API (if omitted, a search of standard paths is performed)"</span>)]</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    [string]$EWSManagedApiPath = <span style="color: #006080">""</span>,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    [Parameter(Mandatory=$False,HelpMessage=<span style="color: #006080">"Whether to ignore any SSL errors (e.g. invalid certificate)"</span>)]</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    [<span style="color: #0000ff">switch</span>]$IgnoreSSLCertificate,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    [Parameter(Mandatory=$False,HelpMessage=<span style="color: #006080">"Bitness of Outlook and Windows"</span>)]</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    [string]$Bitness = <span style="color: #006080">"x32on64"</span>,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    [Parameter(Mandatory=$False,HelpMessage=<span style="color: #006080">"Log file - activity is logged to this file if specified"</span>)]</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    [string]$LogFile = <span style="color: #006080">""</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">[string]$info = <span style="color: #006080">"White"</span>                <span style="color: #008000"># Color for informational messages</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">[string]$warning = <span style="color: #006080">"Yellow"</span>            <span style="color: #008000"># Color for warning messages</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">[string]$error = <span style="color: #006080">"Red"</span>                 <span style="color: #008000">#Color for error messages</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">[string]$success = <span style="color: #006080">"Green"</span>             <span style="color: #008000"># Color for success messages</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">[string]$LogFile = <span style="color: #006080">"Log.txt"</span>   <span style="color: #008000"># Path of the Log File</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">[string]$RegFile = <span style="color: #006080">"CustomFormKeys.reg"</span>   <span style="color: #008000"># Path of the Reg File</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000"># Define our functions</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">Function Log([string]$Details, [ConsoleColor]$Colour)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">{</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> ($Colour <span style="color: #cc6633">-eq</span> $null)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        $Colour = [ConsoleColor]::White</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> ($verbose)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    {    Write-Host $Details -ForegroundColor $Colour }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> ( $LogFile <span style="color: #cc6633">-eq</span> <span style="color: #006080">""</span> ) { <span style="color: #0000ff">return</span>    }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    (Get-Date).ToString()+<span style="color: #006080">" "</span>+ $Details | Out-File $LogFile -Append</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">}</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">Function LoadEWSManagedAPI()</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">{</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #008000"># Find and load the managed API</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> ( ![string]::IsNullOrEmpty($EWSManagedApiPath) )</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        <span style="color: #0000ff">if</span> ( Test-Path $EWSManagedApiPath )</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            Add-Type -Path $EWSManagedApiPath</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            <span style="color: #0000ff">return</span> $true</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        Write-Host ( [string]::Format(<span style="color: #006080">"Managed API not found at specified location: {0}"</span>, $EWSManagedApiPath) ) -ForegroundColor $error</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $a = Get-ChildItem -Recurse <span style="color: #006080">"C:\Program Files (x86)\Microsoft\Exchange\Web Services"</span> -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer <span style="color: #cc6633">-eq</span> $false) -and ( $_.Name <span style="color: #cc6633">-eq</span> <span style="color: #006080">"Microsoft.Exchange.WebServices.dll"</span> ) }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> (!$a)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        $a = Get-ChildItem -Recurse <span style="color: #006080">"C:\Program Files\Microsoft\Exchange\Web Services"</span> -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer <span style="color: #cc6633">-eq</span> $false) -and ( $_.Name <span style="color: #cc6633">-eq</span> <span style="color: #006080">"Microsoft.Exchange.WebServices.dll"</span> ) }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> ($a)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        <span style="color: #008000"># Load EWS Managed API</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        Write-Host ([string]::Format(<span style="color: #006080">"Using managed API {0} found at: {1}"</span>, $a.VersionInfo.FileVersion, $a.VersionInfo.FileName)) -ForegroundColor $success</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        Add-Type -Path $a.VersionInfo.FileName</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        <span style="color: #0000ff">return</span> $true</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #0000ff">return</span> $false</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">}</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">Function SearchOrganizationalFormsLibrary()</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">{</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #008000"># Set EWS URL if specified, or use autodiscover if no URL specified.</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> ($EwsUrl)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        $service.URL = New-Object Uri($EwsUrl)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $LogExists = Test-Path $LogFile</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> ($LogExists){Remove-Item  $LogFile}</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $RegExists = Test-Path $RegFile</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> ($RegExists){Remove-Item  $RegFile}</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $nl = [Environment]::NewLine</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $RegFixFile = $null;</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> ($Bitness)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        <span style="color: #0000ff">if</span> ($Bitness <span style="color: #cc6633">-eq</span> <span style="color: #006080">"x32on64"</span>)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            $RegFixFile=<span style="color: #006080">"Windows Registry Editor Version 5.00"</span> + $nl + <span style="color: #006080">"[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\16.0\Outlook\Security]"</span> + $nl + <span style="color: #006080">"`"</span>DisableCustomFormItemScript`<span style="color: #006080">"=dword:00000000"</span> + $nl +</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            <span style="color: #006080">"[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\16.0\Outlook\Forms\TrustedFormScriptList]"</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        <span style="color: #0000ff">else</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            $RegFixFile=<span style="color: #006080">"Windows Registry Editor Version 5.00"</span> + $nl + <span style="color: #006080">"[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\16.0\Outlook\Security]"</span> + $nl + <span style="color: #006080">"`"</span>DisableCustomFormItemScript`<span style="color: #006080">"=dword:00000000"</span> + $nl +</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            <span style="color: #006080">"[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\16.0\Outlook\Forms\TrustedFormScriptList]"</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        Log <span style="color: #006080">"Looking for Custom Forms.."</span> $info</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #008000">#Bind to the Public Folders Root</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $PFRoot = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #008000">#$PFRoot</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #008000">#Get to Its Parent</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $ParentofPFRoot = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$PFRoot.ParentFolderId)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #008000">#Folder View</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $oFolderView = new-object Microsoft.Exchange.WebServices.Data.FolderView(10)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #008000">#Item View</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $PR_OAB_NAME = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x6800,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String);</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $oItemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(500)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $oItemView.PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet(</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        [Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        [Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        $PR_OAB_NAME)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $oItemView.Traversal = [Microsoft.Exchange.WebServices.Data.ItemTraversal]::Associated</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $oFindFolderResults = $service.FindFolders($ParentofPFRoot.Id,$oFolderView)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #008000">#Now Bind to the NON_IPM_SUBTREE</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $NON_IPM_SUBTREE = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$oFindFolderResults.Folders[1].Id)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    ForEach ($subFolder <span style="color: #0000ff">in</span> $NON_IPM_SUBTREE.FindFolders($oFolderView))</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        <span style="color: #0000ff">if</span> ($subFolder.DisplayName <span style="color: #cc6633">-eq</span> <span style="color: #006080">"EFORMS REGISTRY"</span>)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            <span style="color: #008000">#Get to the "Organizational Forms Library"</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            $oFindFolderResultsOFL = $service.FindFolders($subFolder.Id,$oFolderView)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            <span style="color: #008000">#Look at the associated contents folder..</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            $results = $service.FindItems( $oFindFolderResultsOFL.Folders[0].Id, $oItemView )</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            $RegFixFile | Out-File $RegFile -Append</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            Log <span style="color: #006080">"Looping through the Messages..."</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            ForEach ($item <span style="color: #0000ff">in</span> $results.Items)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">                $FormMessageClass =$null;</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">                <span style="color: #0000ff">if</span> ($Item.TryGetProperty($PR_OAB_NAME,[ref] $FormMessageClass))</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">                {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">                    <span style="color: #008000">#Generate the RegKeys..                </span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">                    Log([string]::Format(<span style="color: #006080">"Creating Key for :{0}"</span>, $FormMessageClass))</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">                    Write-Host ([string]::Format(<span style="color: #006080">"Creating Key for :{0}"</span>, $FormMessageClass)) -ForegroundColor $success</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">                    <span style="color: #006080">'"'</span> + $FormMessageClass +<span style="color: #006080">'"'</span>+ <span style="color: #006080">"="</span> +<span style="color: #006080">'"'</span> + <span style="color: #006080">'"'</span> |Out-File $RegFile -Append</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">                }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    Log <span style="color: #006080">"Done!"</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">}</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">Function TrustAllCerts() {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    &lt;<span style="color: #008000">#</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    .SYNOPSIS</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    Set certificate trust policy to trust self-signed certificates (<span style="color: #0000ff">for</span> test servers).</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #008000">#&gt;</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #008000">## Code From https://poshcode.org/624</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    <span style="color: #008000">## Create a compilation environment</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $Provider=New-Object Microsoft.CSharp.CSharpCodeProvider</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $Compiler=$Provider.CreateCompiler()</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $Params=New-Object System.CodeDom.Compiler.CompilerParameters</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $Params.GenerateExecutable=$False</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $Params.GenerateInMemory=$True</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $Params.IncludeDebugInformation=$False</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $Params.ReferencedAssemblies.Add(<span style="color: #006080">"System.DLL"</span>) | Out-Null</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $TASource=@<span style="color: #006080">'</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        namespace Local.ToolkitExtensions.Net.CertificatePolicy {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        public class TrustAll : System.Net.ICertificatePolicy {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            public TrustAll()</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            public bool CheckValidationResult(System.Net.ServicePoint sp,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">                                                System.Security.Cryptography.X509Certificates.X509Certificate cert,</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">                                                System.Net.WebRequest req, int problem)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">                return true;</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">'@</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $TAAssembly=$TAResults.CompiledAssembly</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #008000">## We now create an instance of the TrustAll and attach it to the ServicePointManager</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $TrustAll=$TAAssembly.CreateInstance(<span style="color: #006080">"Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll"</span>)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">}</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"><span style="color: #008000"># The following is the main script</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000"># Check if we need to ignore any certificate errors</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"><span style="color: #008000"># This needs to be done *before* the managed API is loaded, otherwise it doesn't work consistently (i.e. usually doesn't!)</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #0000ff">if</span> ($IgnoreSSLCertificate)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">{</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    Write-Host <span style="color: #006080">"WARNING: Ignoring any SSL certificate errors"</span> -foregroundColor Yellow</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    TrustAllCerts</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">}</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000"># Load EWS Managed API</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"><span style="color: #0000ff">if</span> (!(LoadEWSManagedAPI))</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">{</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    Write-Host <span style="color: #006080">"Failed to locate EWS Managed API, cannot continue"</span> -ForegroundColor $error</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    Exit</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">}</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"><span style="color: #008000">#Create the service Object.</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"><span style="color: #008000"># Set credentials if specified, or use logged on user.</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"> <span style="color: #0000ff">if</span> ($AuthUsername -and $AuthPassword)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"> {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    Write-Host <span style="color: #006080">"Applying given Credentials for:"</span>, $AuthUsername -ForegroundColor $info</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    <span style="color: #0000ff">if</span> ($AuthDomain)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        $service.Credentials = New-Object  Microsoft.Exchange.WebServices.Data.WebCredentials($AuthUsername,$AuthPassword,$AuthDomain)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    } <span style="color: #0000ff">else</span> {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        $service.Credentials = New-Object  Microsoft.Exchange.WebServices.Data.WebCredentials($AuthUsername,$AuthPassword)</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">} <span style="color: #0000ff">else</span> {</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    Write-Host <span style="color: #006080">"Using default credentials"</span> -ForegroundColor Gray</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    $service.UseDefaultCredentials = $true</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"> }</pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">Write-Host <span style="color: #006080">""</span></pre>
<!--CRLF-->
<pre style="font-size: 8pt;overflow: visible;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">SearchOrganizationalFormsLibrary</pre>
<!--CRLF-->

</div>
</div>
By default the script will generate a .reg file for 32 bit Outlook on 64 bit Windows. If you want it for 64 bit Outlook on 64 bit Windows or 32 bit Outlook on 32 bit Windows, just specify -Bitness “x64on64” or -Bitness “x32on32”  in the command like below (technically an value other than “x32on64” will work).

Sample command line below:

.\DumpMessageClassforForms.ps1 -AuthUsername admin –AuthPassword Pa$$w0rd –AuthDomain contoso -EwsUrl <a href="https://ex2013.contoso.com/ews/exchange.asmx">https://ex2013.contoso.com/ews/exchange.asmx</a>
-IgnoreSSLCertificate

The registry file will be generated in the same folder where the script is run from.

Enjoy!]]></content:encoded>
    </item>
    <item>
      <title>[EWS]Using Oauth authentication with EWS and impersonation in Office 365</title>
      <link>https://docs.microsoft.com/archive/blogs/devmsg/ewsusing-oauth-authentication-with-ews-and-impersonation-in-office-365</link>
      <pubDate>Mon, 25 Jan 2016 11:21:11 GMT</pubDate>
      <dc:creator><![CDATA[Manish Kumar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devmsg/2016/01/25/ewsusing-oauth-authentication-with-ews-and-impersonation-in-office-365/</guid>
      <description><![CDATA[Earlier I shared the sample script for consuming EWS using Oauth (via Azure Active Directory (AAD))...]]></description>
      <content:encoded><![CDATA[Earlier I shared the <a href="https://blogs.msdn.com/b/devmsg/archive/2015/10/29/ews-using-oauth-authentication-with-ews-in-office-365.aspx">sample script</a> for consuming EWS using Oauth (via Azure Active Directory (AAD)) in a delegation mode. Here I’m sharing a sample PowerShell script that illustrates using Oauth authentication with EWS and impersonation to access mailboxes with an app token. The script accesses the mailboxes with email addresses presented in a text file. It then outputs the total item count in Inbox folder and prints the subject of the last five items in Inbox for each of these mailboxes. The authorization grant flow used is Client Credential grant flow and it requires the global admin to gives assent to the app.

Additionally, the app must use an X.509 certificate with a public/private key pair. In this example, I’ll be using a self-issued certificate. The detailed steps for creating a self-issued certificate and uploading the details to manifest in Azure Management Portal are discussed <a href="https://blogs.msdn.microsoft.com/exchangedev/2015/01/21/building-daemon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow/">here</a>.

Coming to permissions, since this app will be using EWS with impersonation, the app has to be provided Exchange scope permissions (Application Permissions under Office 365 Exchange Online): full_access_as_app – "Use Exchange Web Services with full access to all mailboxes”. For detailed steps related to manual app registration in AAD, please see this <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-v1-add-azure-ad-app#adding-an-application">article</a>.

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/60/80/metablogapi/1030.Correct-permission_26E50582.jpg"><img title="Correct permission" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" border="0" alt="Correct permission" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/60/80/metablogapi/4118.Correct-permission_thumb_5FFE7335.jpg" width="489" height="218" /></a>

The UserAccounts.txt present in the same directory as the PowerShell script will contain the email addresses of the impersonated users as shown below:
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">EmailAddress</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">User1@domain.onmicrosoft.com</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">User2@domain.onmicrosoft.com</pre>
<!--CRLF-->

</div>
</div>
The script will need the following:

1. ADAL .NET libraries

2. EWS Managed API dll (version 2.2)

3. UserAccounts.txt file containing the email addresses as described above

4. The password required to access the X.509 certificate data

5. The certificate pfx file

6. Write permission to the directory where the EWS request and response logs will be written

7. Information related to the app you’ve registered in the Azure AD (see script for more details)

There are couple of important things to note here from EWS point of view:

a. Since this script is using EWS impersonation, the request must contain the ExchangeImpersonation header

b. The “X-AnchorMailbox” header needs to be present with the value as the email address of the impersonated account. If the header is not present, you may get an error – “Exchange Web Services are not currently available for this request because none of the Client Access Servers in the destination site could process the request."

Here is the script -
<div id="codeSnippetWrapper" style="overflow: auto;cursor: text;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 97.5%;direction: ltr;text-align: left;margin: 20px 0px 10px;line-height: 12pt;max-height: 200px;background-color: #f4f4f4;border: silver 1px solid;padding: 4px">
<div id="codeSnippet" style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">#NOTE - Disclaimer</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"> #Following programming examples is for illustration only, without warranty either expressed or implied,</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"> #including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose.</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"> #This sample code assumes that you are familiar with the programming language being demonstrated and the tools</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"> #used to create and debug procedures. This sample code is provided for the purpose of illustration only and is</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"> #not intended to be used in a production environment.</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">function GetEmailFromInbox($smtpemailaddress)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">{</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">"Mailbox being accessed: " + $smtpemailaddress</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$service.httpheaders.Add("X-AnchorMailbox", $smtpemailaddress)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress,$smtpemailaddress)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">"Total Messages : " + $inbox.TotalCount</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView(5)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$findItemResults = $service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$view)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">"Printing subject of last five items from Inbox:"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$item = [Microsoft.Exchange.WebServices.Data.Item]</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$i = 1</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">foreach ($item in $findItemResults)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">{</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">"Subject " + $i + ": " + $item.Subject</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$i = $i + 1</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">}</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$bool = $service.httpheaders.Remove("X-AnchorMailbox")</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$service.ImpersonatedUserId = $null</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">}</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$Assem = (</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    "Microsoft.Exchange.WebServices, Version=15.0.0.0, Culture=neutral,  PublicKeyToken =31bf3856ad364e35" #EWS Managed API 2.2</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">   )</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$Source = @"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">using System;</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">using System.Text;</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">using Microsoft.Exchange.WebServices.Data;</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">public class TraceListener : Microsoft.Exchange.WebServices.Data.ITraceListener</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        public void Trace(string traceType, string traceMessage)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            CreateXMLTextFile(traceType, traceMessage.ToString());</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        private void CreateXMLTextFile(string fileName, string traceContent)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            //The path to the EWS request and response log. Please make sure you've write permission to the path/folder specified</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            string strPath = "C:\\EWSLog.txt";</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            System.IO.FileStream fs;</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            if (System.IO.File.Exists(strPath) == false)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">                fs = System.IO.File.Create(strPath);</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            else</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">                fs = System.IO.File.OpenWrite(strPath);</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            fs.Close();</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            // Create an instance of StreamWriter to write text to a file.</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            System.IO.StreamWriter sw = System.IO.File.AppendText(strPath);</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">            sw.WriteLine(System.DateTime.Now.ToString() + ": " + traceContent);</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">            sw.Close();</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">"@</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Load ADAL Assemblies</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$adal = "C:\Nugets\Microsoft.IdentityModel.Clients.ActiveDirectory.2.19.208020213\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$adalforms = "C:\Nugets\Microsoft.IdentityModel.Clients.ActiveDirectory.2.19.208020213\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">[System.Reflection.Assembly]::LoadFrom($adal)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">[System.Reflection.Assembly]::LoadFrom($adalforms)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Set Azure AD Tenant name (not needed here)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$adTenant = "domain.onmicrosoft.com"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Set well-known client ID from Azure AD for this application</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$clientId = "client id"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Set redirect URI from Azure AD for this application</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$redirectUri = "reply url"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Set Resource URI to Office 365 in this case</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$resourceAppIdURI = "https://outlook.office365.com/"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Set Authority to Azure AD Tenant</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">#https://stackoverflow.com/questions/26384034/how-to-get-the-azure-account-tenant-id</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$authority = "https://login.windows.net/<span style="color: #0000ff">&lt;</span><span style="color: #800000">tenant-id</span><span style="color: #0000ff">&gt;</span>/oauth2/authorize"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Create Authentication Context tied to Azure AD Tenant</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Acquire token</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">#Provide the name of the certificate file</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$certfile = "C:\CertPrivatekey.pfx"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$flag = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">#Provide the password required to access the X.509 certificate data</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$cert  = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certfile, "password", $flag )</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$cac = New-Object  Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate($clientID, $cert)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$authResult = $authContext.AcquireToken($resourceAppIdURI, $cac)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">write-host "Access token:   " $authResult.AccessToken</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"># EWS</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">## Code From https://poshcode.org/624</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">## Create a compilation environment</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$Provider=New-Object Microsoft.CSharp.CSharpCodeProvider</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$Compiler=$Provider.CreateCompiler()</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$Params=New-Object System.CodeDom.Compiler.CompilerParameters</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$Params.GenerateExecutable=$False</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$Params.GenerateInMemory=$True</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$Params.IncludeDebugInformation=$False</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$Params.ReferencedAssemblies.Add("System.DLL") | Out-Null</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$TASource=@'</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">  namespace Local.ToolkitExtensions.Net.CertificatePolicy{</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    public class TrustAll : System.Net.ICertificatePolicy {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">      public TrustAll() {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">      }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">      public bool CheckValidationResult(System.Net.ServicePoint sp,</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        System.Security.Cryptography.X509Certificates.X509Certificate cert,</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        System.Net.WebRequest req, int problem) {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        return true;</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">      }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">  }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">'@</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$TAAssembly=$TAResults.CompiledAssembly</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">## We now create an instance of the TrustAll and attach it to the ServicePointManager</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">[System.Net.ServicePointManager]::CertificatePolicy=$TrustAll</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$service.TraceListener = new-object TraceListener</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">#Set it to $false, if you want to disable this tracing</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$service.TraceEnabled = $true</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$service.Url = new-object System.Uri("https://outlook.office365.com/ews/exchange.asmx")</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$service.Credentials  = new-object  Microsoft.Exchange.WebServices.Data.OAuthCredentials($authResult.AccessToken)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">import-csv UserAccounts.txt | foreach-object {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    $EmailAddress = $_.EmailAddress.ToString()</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    GetEmailFromInbox($EmailAddress)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>
<!--CRLF-->

</div>
</div>
Happy scripting!]]></content:encoded>
    </item>
    <item>
      <title>[EWS]Using Oauth authentication with EWS in Office 365</title>
      <link>https://docs.microsoft.com/archive/blogs/devmsg/ewsusing-oauth-authentication-with-ews-in-office-365</link>
      <pubDate>Thu, 29 Oct 2015 11:04:47 GMT</pubDate>
      <dc:creator><![CDATA[Manish Kumar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devmsg/2015/10/29/ewsusing-oauth-authentication-with-ews-in-office-365/</guid>
      <description><![CDATA[I’m sharing a PowerShell script sample that illustrates using Oauth authentication via Azure Active...]]></description>
      <content:encoded><![CDATA[I’m sharing a PowerShell script sample that illustrates using Oauth authentication via Azure Active Directory (AAD) and EWS to connect to Office 365 mailbox. The script outputs the total item count in Inbox folder and prints the subject of the last five items in Inbox. The authorization grant flow used is Authorization code grant flow which means the user gives assent to the app to access his own mailbox.

There are couple of blogs I’m referring below that helped in putting up this script.

1. For loading Active Directory Authentication Library
<a href="https://www.dushyantgill.com/blog/2013/12/27/aadgraphpowershell-a-powershell-client-for-windows-azure-ad-graph-api/">https://www.dushyantgill.com/blog/2013/12/27/aadgraphpowershell-a-powershell-client-for-windows-azure-ad-graph-api/</a>

2. Acquiring the token
<a href="https://blogs.technet.com/b/keithmayer/archive/2014/12/30/authenticating-to-the-azure-service-management-rest-api-using-azure-active-directory-via-powershell-list-azure-administrators.aspx" title="https://blogs.technet.com/b/keithmayer/archive/2014/12/30/authenticating-to-the-azure-service-management-rest-api-using-azure-active-directory-via-powershell-list-azure-administrators.aspx">https://blogs.technet.com/b/keithmayer/archive/2014/12/30/authenticating-to-the-azure-service-management-rest-api-using-azure-active-directory-via-powershell-list-azure-administrators.aspx</a>

Please note that the application registered in AAD is a native client application (not a web app). For detailed steps related to manual app registration in AAD, please see this <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-v1-add-azure-ad-app#adding-an-application">article</a>. The permission provided is Exchange scope permissions (Delegated permissions under Office 365 Exchange Online): full_access_as_user – Access mailbox as signed in user via Exc…”

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/60/80/metablogapi/6366.EWSpermissioninAAD_39FC5B94.png"><img title="EWS permission in AAD" style="border-width: 0px" border="0" alt="EWS permission in AAD" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/60/80/metablogapi/1588.EWSpermissioninAAD_thumb_02B5D459.png" width="702" height="420" /></a>
<div id="codeSnippetWrapper" style="overflow: auto;cursor: text;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 97.5%;direction: ltr;text-align: left;margin: 20px 0px 10px;line-height: 12pt;max-height: 200px;background-color: #f4f4f4;border: silver 1px solid;padding: 4px">
<div id="codeSnippet" style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">#NOTE - Disclaimer</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">#Following programming examples is for illustration only, without warranty either expressed or implied,</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">#including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose.</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">#This sample code assumes that you are familiar with the programming language being demonstrated and the tools</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">#used to create and debug procedures. This sample code is provided for the purpose of illustration only and is</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">#not intended to be used in a production environment.</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Load ADAL Assemblies</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$adal = "C:\Nugets\Microsoft.IdentityModel.Clients.ActiveDirectory.2.19.208020213\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$adalforms = "C:\Nugets\Microsoft.IdentityModel.Clients.ActiveDirectory.2.19.208020213\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">[System.Reflection.Assembly]::LoadFrom($adal)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">[System.Reflection.Assembly]::LoadFrom($adalforms)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Set Azure AD Tenant name; not used in this script</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$adTenant = "domain.onmicrosoft.com"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Set well-known client ID from Azure AD for this application</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"># It is in the form of a guid 1a2b34c5-da6b-7777-ef8a-g9h001i23456</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$clientId = "client-id"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"># Set redirect URI from Azure AD for this application</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">#e.g https://myapp/reply</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$redirectUri = "reply-url"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Set Resource URI to Office 365 in this case</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$resourceAppIdURI = "https://outlook.office365.com/"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"># Set Authority to Azure AD Tenant</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">#https://stackoverflow.com/questions/26384034/how-to-get-the-azure-account-tenant-id</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$authority = "https://login.windows.net/<span style="color: #0000ff">&lt;</span><span style="color: #800000">tenant-id</span><span style="color: #0000ff">&gt;</span>/oauth2/authorize"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"># Create Authentication Context tied to Azure AD Tenant</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"># Acquire token</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto")</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">## Code From https://poshcode.org/624</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">## Create a compilation environment</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$Provider=New-Object Microsoft.CSharp.CSharpCodeProvider</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$Compiler=$Provider.CreateCompiler()</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$Params=New-Object System.CodeDom.Compiler.CompilerParameters</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$Params.GenerateExecutable=$False</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$Params.GenerateInMemory=$True</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$Params.IncludeDebugInformation=$False</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$Params.ReferencedAssemblies.Add("System.DLL") | Out-Null</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$TASource=@'</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">  namespace Local.ToolkitExtensions.Net.CertificatePolicy{</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    public class TrustAll : System.Net.ICertificatePolicy {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">      public TrustAll() {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">      }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">      public bool CheckValidationResult(System.Net.ServicePoint sp,</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        System.Security.Cryptography.X509Certificates.X509Certificate cert,</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">        System.Net.WebRequest req, int problem) {</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">        return true;</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">      }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">    }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">  }</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">'@</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$TAAssembly=$TAResults.CompiledAssembly</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">## We now create an instance of the TrustAll and attach it to the ServicePointManager</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">[System.Net.ServicePointManager]::CertificatePolicy=$TrustAll</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$service.Url = new-object System.Uri("https://outlook.office365.com/ews/exchange.asmx")</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$service.Credentials  = new-object  Microsoft.Exchange.WebServices.Data.OAuthCredentials($authResult.AccessToken)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">"Total items in Inbox : " + $inbox.TotalCount</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView(5)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$findItemResults = $service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$view)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">"Printing subject of last five items from Inbox:"</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$item = [Microsoft.Exchange.WebServices.Data.Item]</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">$i = 1</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px"></pre>

<!--CRLF-->

<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">foreach ($item in $findItemResults)</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">{</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">"Subject " + $i + ": " + $item.Subject</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">$i = $i + 1</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: white;border-style: none;padding: 0px">""</pre>
<!--CRLF-->
<pre style="overflow: visible;font-size: 8pt;font-family: 'Courier New', courier, monospace;width: 100%;color: black;direction: ltr;text-align: left;margin: 0em;line-height: 12pt;background-color: #f4f4f4;border-style: none;padding: 0px">}</pre>
<!--CRLF-->

</div>
</div>
Read more about EWS and Oauth authentication <a href="https://msdn.microsoft.com/EN-US/library/office/dn903761(v=exchg.150).aspx">here</a>.

Happy scripting!]]></content:encoded>
    </item>
    <item>
      <title>Get Started with Exchange Online REST APIs for Office 365 development in .NET</title>
      <link>https://docs.microsoft.com/archive/blogs/devmsg/get-started-with-exchange-online-rest-apis-for-office-365-development-in-net</link>
      <pubDate>Mon, 12 Oct 2015 13:48:19 GMT</pubDate>
      <dc:creator><![CDATA[Manish Kumar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devmsg/2015/10/12/get-started-with-exchange-online-rest-apis-for-office-365-development-in-net/</guid>
      <description><![CDATA[If you intend to try your hands on building an application that interacts with Exchange Online...]]></description>
      <content:encoded><![CDATA[<p>   <br />If you intend to try your hands on building an application that interacts with Exchange Online and utilizes Office 365 REST APIs for mail, calendars, and contacts, the steps below should help. </p>  <ol>   <li>Get your <a href="https://portal.office.com/Signup/Signup.aspx?OfferId=6881A1CB-F4EB-4db3-9F18-388898DAF510&amp;DL=DEVELOPERPACK&amp;ali=1#0">Office 365 tenant developer account</a> (if you need more than one license, link your tenant to <a href="https://portal.office.com/Signup/Signup.aspx?OfferId=B07A1127-DE83-4a6d-9F85-2C104BDAE8B4&amp;dl=ENTERPRISEPACK&amp;ali=1#0">30 days free trial of Office</a>)       <br />      <br /></li>    <li>Add an Azure subscription – you can use your MSDN subscription for it      <br />      <br /><a href="https://msdn.microsoft.com/subscriptions/manage/default.aspx">https://msdn.microsoft.com/subscriptions/manage/default.aspx</a>       <br />      <br /><a href="https://msdn.microsoft.com/en-us/subscriptions/dn531048.aspx">https://msdn.microsoft.com/en-us/subscriptions/dn531048.aspx</a>       <br />      <br />Getting Started with Your MSDN Subscription       <br /><a href="https://msdn.microsoft.com/en-us/library/dd364989.aspx">https://msdn.microsoft.com/en-us/library/dd364989.aspx</a>       <br />      <br /></li>    <li>Register your app in Azure AD and add appropriate permissions:      <br />      <br />a. From Visual Studio 2013 using Connected service: <a href="https://msdn.microsoft.com/office/office365/HowTo/adding-service-to-your-Visual-Studio-project">https://msdn.microsoft.com/office/office365/HowTo/adding-service-to-your-Visual-Studio-project</a> and <a href="https://blogs.msdn.com/b/visualstudio/archive/2014/11/19/connecting-to-cloud-services.aspx">https://blogs.msdn.com/b/visualstudio/archive/2014/11/19/connecting-to-cloud-services.aspx</a>       <br />      <br />b. From Windows Azure portal for O365 (to manually register it): <a href="https://msdn.microsoft.com/office/office365/HowTo/add-common-consent-manually">https://msdn.microsoft.com/office/office365/HowTo/add-common-consent-manually</a>       <br />      <br />c. Outlook Dev Portal App Registration Tool       <br /><a href="https://dev.outlook.com/AppRegistration">https://dev.outlook.com/AppRegistration</a>       <br />      <br /></li>    <li>Build your application. If you are using Visual Studio to do so, you’ll need to install <a href="https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory/">ADAL library through Nuget</a>. Please also make sure you use .NET 4.5 or above if you are using latest ADAL library. </li> </ol>  <p><b></b></p>  <p><b></b></p>  <p><b>     <br />Tools</b> you can use to understand how the flow works. You’ve an option to play with sample data or sign in and work with your own Office 365 tenant account.     <br />(Only for authorization grant flow) </p>  <ol>   <li><a href="https://apisandbox.msdn.microsoft.com/">Apisandbox</a>       <br />      <br /></li>    <li><a href="https://oauthplay.azurewebsites.net/">Oauthplay</a> </li> </ol>  <p><b></b></p>  <p><b>     <br />Understanding Permissions:       <br />      <br /></b>Office 365 application manifest and permission details     <br /><a href="https://msdn.microsoft.com/office/office365/HowTo/application-manifest">https://msdn.microsoft.com/office/office365/HowTo/application-manifest</a>     <br /><b>     <br />      <br />Understanding Oauth grant flows:       <br />      <br /></b>There are two grant flows: </p>  <ol>   <li>Authorization code grant flow – this is said to run in delegation mode. The user gives assent to the app to access his own mailbox.      <br />      <br />Please see <a href="https://blogs.msdn.com/b/exchangedev/archive/2014/09/24/10510847.aspx">https://blogs.msdn.com/b/exchangedev/archive/2014/09/24/10510847.aspx</a> and <a href="https://msdn.microsoft.com/en-us/library/azure/dn645543.aspx">https://msdn.microsoft.com/en-us/library/azure/dn645543.aspx</a>       <br />      <br /></li>    <li>Client Credential flow – this is said to run in app-only mode. Also known as Daemon app or service app. The admin (tenant administrator/ global administrator) needs to give assent to the app.      <br />      <br />Please see <a href="https://msdn.microsoft.com/en-us/library/azure/dn645543.aspx">https://msdn.microsoft.com/en-us/library/azure/dn645543.aspx</a> and <a href="https://blogs.msdn.com/b/exchangedev/archive/2015/01/22/building-demon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow.aspx">https://blogs.msdn.com/b/exchangedev/archive/2015/01/22/building-demon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow.aspx</a> </li> </ol>  <p><b>     <br />Important Samples in .NET:       <br />      <br /></b>Authorization grant flow:     <br /><a href="https://dev.outlook.com/RestGettingStarted/Tutorial/dotnet">https://dev.outlook.com/RestGettingStarted/Tutorial/dotnet</a>     <br />    <br />Client credential flow:     <br /><a href="https://github.com/mattleib/o365api-as-apponly-webapp">https://github.com/mattleib/o365api-as-apponly-webapp</a></p>]]></content:encoded>
    </item>
    <item>
      <title>[EWS]How To enable EWS request and response tracing in PowerShell script using EWS Managed API?</title>
      <link>https://docs.microsoft.com/archive/blogs/devmsg/ewshow-to-enable-ews-request-and-response-tracing-in-powershell-script-using-ews-managed-api</link>
      <pubDate>Fri, 02 Oct 2015 15:10:24 GMT</pubDate>
      <dc:creator><![CDATA[Manish Kumar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devmsg/2015/10/02/ewshow-to-enable-ews-request-and-response-tracing-in-powershell-script-using-ews-managed-api/</guid>
      <description><![CDATA[Most of the time we need to review the request and response logs when troubleshooting any...]]></description>
      <content:encoded><![CDATA[<p>Most of the time we need to review the request and response logs when troubleshooting any application/script which is utilizing the Exchange Web Services. Although setting the TraceEnabled flag to true on the ExchangeService object outputs the trace to the PowerShell window, there is no easy way to copy the trace to a file. Below is an example of using the inbuilt tracing capabilities of the EWS Managed API to enable the logging of request and response in a text file. Here the assembly version and PublicKeyToken correspond to the Microsoft.Exchange.WebServices.dll obtained after installing EWS Managed API 2.2 from <a title="https://www.microsoft.com/en-in/download/details.aspx?id=42951" href="https://www.microsoft.com/en-in/download/details.aspx?id=42951">https://www.microsoft.com/en-in/download/details.aspx?id=42951</a>. For a different Managed API version, you need to update the version and PublicKeyToken accordingly. </p>  <p>To-do: In the line number 17, change the log file path to your liking and also provide the file name. I’ve used C: directory as the log file path and Log as the name of the file. There could be permission issues when creating the log file in a directory. So make sure you’ve the permission to create a new file and write to it in the log file directory or run the PowerShell window as an administrator. </p>  <p>NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment. </p>  <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">   <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">     <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> $Assem = ( </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span>     &quot;Microsoft.Exchange.WebServices, Version=15.0.0.0, Culture=neutral,  PublicKeyToken =31bf3856ad364e35&quot;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>    ) </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span> $Source = @&quot;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span> using System;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span> using System.Text;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span> using Microsoft.Exchange.WebServices.Data;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span> public class TraceListener : Microsoft.Exchange.WebServices.Data.ITraceListener</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>     {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span>         public void Trace(string traceType, string traceMessage)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span>         {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060">  13:</span>             CreateXMLTextFile(traceType, traceMessage.ToString());</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span>         }</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060">  15:</span>         private void CreateXMLTextFile(string fileName, string traceContent)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060">  16:</span>         {           </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060">  17:</span>            string strPath = &quot;C:\\Log.txt&quot;;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum18" style="color: #606060">  18:</span>             System.IO.FileStream fs;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum19" style="color: #606060">  19:</span>             if (System.IO.File.Exists(strPath) == false)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum20" style="color: #606060">  20:</span>             {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum21" style="color: #606060">  21:</span>                 fs = System.IO.File.Create(strPath);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum22" style="color: #606060">  22:</span>             }</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum23" style="color: #606060">  23:</span>             else</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum24" style="color: #606060">  24:</span>             {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum25" style="color: #606060">  25:</span>                 fs = System.IO.File.OpenWrite(strPath);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum26" style="color: #606060">  26:</span>             }</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum27" style="color: #606060">  27:</span>             fs.Close();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum28" style="color: #606060">  28:</span>             // Create an instance of StreamWriter to write text to a file.</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum29" style="color: #606060">  29:</span>             System.IO.StreamWriter sw = System.IO.File.AppendText(strPath);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum30" style="color: #606060">  30:</span>             sw.WriteLine(System.DateTime.Now.ToString() + &quot;: &quot; + traceContent);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum31" style="color: #606060">  31:</span>             sw.Close();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum32" style="color: #606060">  32:</span>         }</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum33" style="color: #606060">  33:</span>     }</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum34" style="color: #606060">  34:</span> &quot;@</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum35" style="color: #606060">  35:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum36" style="color: #606060">  36:</span> Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp  </pre>
<!--CRLF--></div>
</div>

<p>After you add this to the script, you need to assign the TraceListener member of the ExchangeService class to an instance of the above TraceListener class. </p>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> $service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> $service.TraceListener = new-object TraceListener</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> #Set it to $false, if you want to disable this tracing</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span> $service.TraceEnabled = $true </pre>
<!--CRLF--></div>
</div>

<p>In this example we’re loading the assembly into the current PowerShell session. So, if you make any changes to the TraceListener class and run the script again in the same PowerShell session, you may well see an error which indicates that the Type is already loaded [Add-Type : Cannot add type. The type name 'TraceListener' already exists.]. In that case, please restart the Windows PowerShell and run the script. 
  <br />

  <br />Attached at the bottom of this post is the file (EWS tracing PowerShell.txt) containing the above code snippet. 

  <br />

  <br />Happy scripting!</p>

<div id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:bdad107f-d31d-4a41-9abf-869fb3e7a7cc" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><p><div><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/60/80/metablogapi/2772.EWStracingPowerShell_1D5CFD97.txt" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-60-80-metablogapi/2772.EWStracingPowerShell_5F00_1D5CFD97.txt" target="_self">EWS tracing PowerShell.txt</a></div></p></div>]]></content:encoded>
    </item>
    <item>
      <title>NO TO MULTIPLE BODIES ON A MESSAGE!</title>
      <link>https://docs.microsoft.com/archive/blogs/devmsg/no-to-multiple-bodies-on-a-message</link>
      <pubDate>Thu, 07 May 2015 11:42:27 GMT</pubDate>
      <dc:creator><![CDATA[Manish Kumar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devmsg/2015/05/07/no-to-multiple-bodies-on-a-message/</guid>
      <description><![CDATA[Recently I came across a case where the requirement was to send an email (using Outlook Object...]]></description>
      <content:encoded><![CDATA[<p>Recently I came across a case where the requirement was to send an email (using Outlook Object Model) consisting of both HTML and Plain Text body, with the idea being that, based on the View set in outlook, the appropriate body will be chosen. The cause for setting multiple bodies was that, when an email containing image icons are rendered in plain text view, additional URLs were added in the place of the image icons which made the email look clumsy!</p>  <p>Digging further into the issue made me try some troubleshooting to check what exactly is happening. The first test was performed using Outlook Object model with the HTML body format set. Result observed was that for HTML view, the HTML body content was displayed along with the formatting&#160; while for Plain text view, only the HTML body content was displayed without any formatting. Further, test performed using System.Net.Mail with the AlternateView set, proved that Exchange will only store one body in one format and does not support having multiple bodies on a message.</p>  <p>The behavior observed is expected and by design. As per the protocol document, Exchange prefers a certain format, “text/HTML”.&#160; If there is an HTML body part it will be chosen as the Primary Message Text and that is what is converted to MAPI.&#160; When a client asks for PR_BODY (i.e. plain text) it will be converted as per “Best Body” logic. </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/60/80/metablogapi/1145.clip_image002_5F7566E8.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-60-80-metablogapi/1145.clip_5F00_image002_5F00_5F7566E8.jpg"><img title="clip_image002" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/60/80/metablogapi/3731.clip_image002_thumb_3EF0B7E7.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-60-80-metablogapi/3731.clip_5F00_image002_5F00_thumb_5F00_3EF0B7E7.jpg" width="501" height="268" /></a></p>  <p>As a simple work around, rather than referencing external images for the image icons, it is suggested to add them as attachments and reference them in HTML.</p>  <p><b>Reference Links :</b></p>  <p>· Selecting the Primary Message Text MIME Element : <a href="https://msdn.microsoft.com/en-us/library/gg709700%28v=exchg.80%29.aspx">https://msdn.microsoft.com/en-us/library/gg709700%28v=exchg.80%29.aspx</a></p>  <p>· Body Text : <a href="https://msdn.microsoft.com/en-us/library/gg672102%28v=exchg.80%29.aspx">https://msdn.microsoft.com/en-us/library/gg672102%28v=exchg.80%29.aspx</a></p>  <p>· Determining Which MIME Element Is the Message Body : <a href="https://msdn.microsoft.com/en-us/library/gg672007%28v=exchg.80%29.aspx">https://msdn.microsoft.com/en-us/library/gg672007%28v=exchg.80%29.aspx</a></p>  <p>· HTML Text Message Body Without Inline Attachments : <a href="https://msdn.microsoft.com/en-us/library/ee238059%28v=exchg.80%29.aspx">https://msdn.microsoft.com/en-us/library/ee238059%28v=exchg.80%29.aspx</a></p>  <p>· Best Body Algorithm : <a href="https://msdn.microsoft.com/en-us/library/hh369831%28v=exchg.80%29.aspx">https://msdn.microsoft.com/en-us/library/hh369831%28v=exchg.80%29.aspx</a></p>  <p>· Forum link that has a discussion thread for a similar issue <a href="https://social.msdn.microsoft.com/Forums/office/en-US/0c490364-c6f7-40cf-9f6f-b90aea443cda/outlook-email-text-or-html-format-for-recepient?forum=outlookdev">https://social.msdn.microsoft.com/Forums/office/en-US/0c490364-c6f7-40cf-9f6f-b90aea443cda/outlook-email-text-or-html-format-for-recepient?forum=outlookdev</a></p>  <p><b>Kamala Payyapilly Thiruvenkatanathan [MSFT]</b></p>]]></content:encoded>
    </item>
    <item>
      <title>[EWS]How to retrieve the OOF (Out Of Facility) settings/message using EWS for an Exchange user?</title>
      <link>https://docs.microsoft.com/archive/blogs/devmsg/ewshow-to-retrieve-the-oof-out-of-facility-settingsmessage-using-ews-for-an-exchange-user</link>
      <pubDate>Mon, 02 Jun 2014 15:45:31 GMT</pubDate>
      <dc:creator><![CDATA[Manish Kumar - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devmsg/2014/06/02/ewshow-to-retrieve-the-oof-out-of-facility-settingsmessage-using-ews-for-an-exchange-user/</guid>
      <description><![CDATA[Technorati Tags: EWS,Exchange 2010,GetMailTips,GetUserOofSettings,Out of Facility,Out of Office,EWS...]]></description>
      <content:encoded><![CDATA[<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:08113988-0379-4c18-8eb8-016658892bdd" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">Technorati Tags: <a href="https://technorati.com/tags/EWS" rel="tag">EWS</a>,<a href="https://technorati.com/tags/Exchange+2010" rel="tag">Exchange 2010</a>,<a href="https://technorati.com/tags/GetMailTips" rel="tag">GetMailTips</a>,<a href="https://technorati.com/tags/GetUserOofSettings" rel="tag">GetUserOofSettings</a>,<a href="https://technorati.com/tags/Out+of+Facility" rel="tag">Out of Facility</a>,<a href="https://technorati.com/tags/Out+of+Office" rel="tag">Out of Office</a>,<a href="https://technorati.com/tags/EWS+Managed+API" rel="tag">EWS Managed API</a>,<a href="https://technorati.com/tags/Exchange+2013" rel="tag">Exchange 2013</a>,<a href="https://technorati.com/tags/Exchange+Online" rel="tag">Exchange Online</a>,<a href="https://technorati.com/tags/Exchange+Web+Services" rel="tag">Exchange Web Services</a>,<a href="https://technorati.com/tags/DevMsg" rel="tag">DevMsg</a>,<a href="https://technorati.com/tags/HTTP+EWS+SOAP+request" rel="tag">HTTP EWS SOAP request</a></div>  <p>Our customers have a common ask wherein they would like to check if the organization’s employees are available in office or out of office on a given day. With <strong>Exchange Web Services (EWS)</strong> being the flagship API for Exchange related development, the relevant call they come across is <a href="https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.exchangeservice.getuseroofsettings(v=exchg.80).aspx"><strong>GetUserOofSettings</strong></a><strong>&#160;</strong>in <strong>EWS Managed API.</strong></p>  <p>However, when you make this call from a normal Exchange user account, you get an error message saying:    <br /><strong>&quot;Access is denied. Check credentials and try again&quot;. </strong></p>  <p>The reason being <b>GetUserOofSettings </b>call<b> </b>works only for the users with the <a href="https://msdn.microsoft.com/en-us/library/office/bb204095(v=exchg.140).aspx">Exchange impersonation permissions</a>. As for example, assume that the EWS call is made using the User A’s credential and he’s trying to access User B’s OOF settings. In that case, User A needs to have Exchange impersonation permissions on User B’s mailbox.</p>  <p>In case if you’re requirement is not to run the EWS application under impersonation service account then we could use <a href="https://technet.microsoft.com/en-us/library/dd297974.aspx">Mail Tips</a> to fetch the automatic reply set by the Exchange user.     <br />    <br />Currently, we don’t have a EWS Managed API call to retrieve the Mail Tips. However, we have the method GetMailTips operation available with Exchange Web Services to retrieve the out of office settings.     <br />    <br />We can create the soap request for GetMailTips operation in the following ways: </p>  <ul>   <li>Use the Visual Studio to generate the proxy classes for EWS and then use it write the code for GetMailTips operation.      <br /></li>    <li>Post the request directly from your EWS managed API application.      <br />      <br />Here is a sample using EWS Managed API: </li> </ul>  <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">   <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">     <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #008000">/* Disclaimer:</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #008000">By using the following materials or sample code you agree to be bound by the license terms below and the Microsoft Partner Program Agreement the terms of which are incorporated herein by this reference. These license terms are an agreement between Microsoft Corporation (or, if applicable based on where you are located, one of its affiliates) and you. Any materials (other than sample code) we provide to you are for your internal use only. Any sample code is provided for the purpose of illustration only and is not intended to be used in a production environment. We grant you a nonexclusive, royalty-free right to use and modify the sample code and to reproduce and distribute the object code form of the sample code, provided that you agree: (i) to not use Microsoft's name, logo, or trademarks to market your software product in which the sample code is embedded; (ii) to include a valid copyright notice on your software product in which the sample code is embedded; (iii) to provide on behalf of and for the benefit of your subcontractors a disclaimer of warranties, exclusion of liability for indirect and consequential damages and a reasonable limitation of liability; and (iv) to indemnify, hold harmless, and defend Microsoft, its affiliates and suppliers from and against any third party claims or lawsuits, including attorneys' fees, that arise or result from the use or distribution of the sample code.*/</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span> <span style="color: #0000ff">string</span> getMailTipssoapResponse = oofCall(service.Url.AbsoluteUri);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> oofCall(String urlname)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>         {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>             WebRequest webRequest = WebRequest.Create(urlname);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>             HttpWebRequest httpwebRequest = (HttpWebRequest)webRequest;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>             httpwebRequest.Method = <span style="color: #006080">&quot;POST&quot;</span>;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span>             httpwebRequest.ContentType = <span style="color: #006080">&quot;text/xml; charset=utf-8&quot;</span>;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span>             httpwebRequest.ProtocolVersion = HttpVersion.Version11;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060">  13:</span>             httpwebRequest.Credentials = CredentialCache.DefaultCredentials;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span>             httpwebRequest.Timeout = 60000;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060">  15:</span>             Stream requestStream = httpwebRequest.GetRequestStream();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060">  16:</span>             StreamWriter streamWriter = <span style="color: #0000ff">new</span> StreamWriter(requestStream, Encoding.ASCII);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060">  17:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum18" style="color: #606060">  18:</span>             StringBuilder getMailTipsSoapRequest = <span style="color: #0000ff">new</span> StringBuilder(<span style="color: #006080">&quot;&lt;soap:Envelope xmlns:xsi=\&quot;https://www.w3.org/2001/XMLSchema-instance\&quot;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum19" style="color: #606060">  19:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot; xmlns:xsd=\&quot;https://www.w3.org/2001/XMLSchema\&quot; &quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum20" style="color: #606060">  20:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot;xmlns:soap=\&quot;https://schemas.xmlsoap.org/soap/envelope/\&quot; &quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum21" style="color: #606060">  21:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot;xmlns:t=\&quot;https://schemas.microsoft.com/exchange/services/2006/types\&quot;&gt;&lt;soap:Header&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum22" style="color: #606060">  22:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot; &lt;t:RequestServerVersion Version=\&quot;Exchange2010\&quot;/&gt;&lt;/soap:Header&gt;&lt;soap:Body&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum23" style="color: #606060">  23:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot;&lt;GetMailTips xmlns=\&quot;https://schemas.microsoft.com/exchange/services/2006/messages\&quot;&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum24" style="color: #606060">  24:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot;&lt;SendingAs&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum25" style="color: #606060">  25:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot;&lt;t:EmailAddress&gt;user1@contoso.com&lt;/t:EmailAddress&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum26" style="color: #606060">  26:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot;&lt;t:RoutingType&gt;SMTP&lt;/t:RoutingType&gt;&lt;/SendingAs&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum27" style="color: #606060">  27:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot;&lt;Recipients&gt;&lt;t:Mailbox&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum28" style="color: #606060">  28:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot;&lt;t:EmailAddress&gt;user2@contoso.com&lt;/t:EmailAddress&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum29" style="color: #606060">  29:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot;&lt;t:RoutingType&gt;SMTP&lt;/t:RoutingType&gt;&lt;/t:Mailbox&gt;&lt;/Recipients&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum30" style="color: #606060">  30:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot; &lt;MailTipsRequested&gt;OutOfOfficeMessage&lt;/MailTipsRequested&gt;&lt;/GetMailTips&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum31" style="color: #606060">  31:</span>             getMailTipsSoapRequest.Append(<span style="color: #006080">&quot;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum32" style="color: #606060">  32:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum33" style="color: #606060">  33:</span>             streamWriter.Write(getMailTipsSoapRequest.ToString());</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum34" style="color: #606060">  34:</span>             streamWriter.Close();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum35" style="color: #606060">  35:</span>             HttpWebResponse webResponse = (HttpWebResponse)httpwebRequest.GetResponse();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum36" style="color: #606060">  36:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum37" style="color: #606060">  37:</span>             StreamReader streamreader = <span style="color: #0000ff">new</span> StreamReader(webResponse.GetResponseStream());</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum38" style="color: #606060">  38:</span>             <span style="color: #0000ff">string</span> result = streamreader.ReadToEnd();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum39" style="color: #606060">  39:</span>             <span style="color: #0000ff">return</span> result;</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum40" style="color: #606060">  40:</span>         } </pre>
<!--CRLF--></div>
</div>

<p>Here is the response that I got from server:</p>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">=&quot;utf-8&quot;</span> ?<span style="color: #0000ff">&gt;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> - <span style="color: #0000ff">&lt;</span><span style="color: #800000">s:Envelope</span> <span style="color: #ff0000">xmlns:s</span><span style="color: #0000ff">=&quot;https://schemas.xmlsoap.org/soap/envelope/&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> - <span style="color: #0000ff">&lt;</span><span style="color: #800000">s:Header</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">h:ServerVersionInfo</span> <span style="color: #ff0000">MajorVersion</span><span style="color: #0000ff">=&quot;14&quot;</span> <span style="color: #ff0000">MinorVersion</span><span style="color: #0000ff">=&quot;3&quot;</span> <span style="color: #ff0000">MajorBuildNumber</span><span style="color: #0000ff">=&quot;136&quot;</span> <span style="color: #ff0000">MinorBuildNumber</span><span style="color: #0000ff">=&quot;1&quot;</span> <span style="color: #ff0000">Version</span><span style="color: #0000ff">=&quot;Exchange2010_SP2&quot;</span> <span style="color: #ff0000">xmlns:h</span><span style="color: #0000ff">=&quot;https://schemas.microsoft.com/exchange/services/2006/types&quot;</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">=&quot;https://schemas.microsoft.com/exchange/services/2006/types&quot;</span> <span style="color: #ff0000">xmlns:xsi</span><span style="color: #0000ff">=&quot;https://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #ff0000">xmlns:xsd</span><span style="color: #0000ff">=&quot;https://www.w3.org/2001/XMLSchema&quot;</span> <span style="color: #0000ff">/&gt;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">s:Header</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span> - <span style="color: #0000ff">&lt;</span><span style="color: #800000">s:Body</span> <span style="color: #ff0000">xmlns:xsi</span><span style="color: #0000ff">=&quot;https://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #ff0000">xmlns:xsd</span><span style="color: #0000ff">=&quot;https://www.w3.org/2001/XMLSchema&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span> - <span style="color: #0000ff">&lt;</span><span style="color: #800000">GetMailTipsResponse</span> <span style="color: #ff0000">ResponseClass</span><span style="color: #0000ff">=&quot;Success&quot;</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">=&quot;https://schemas.microsoft.com/exchange/services/2006/messages&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">ResponseCode</span><span style="color: #0000ff">&gt;</span>NoError<span style="color: #0000ff">&lt;/</span><span style="color: #800000">ResponseCode</span><span style="color: #0000ff">&gt;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span> - <span style="color: #0000ff">&lt;</span><span style="color: #800000">ResponseMessages</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span> - <span style="color: #0000ff">&lt;</span><span style="color: #800000">MailTipsResponseMessageType</span> <span style="color: #ff0000">ResponseClass</span><span style="color: #0000ff">=&quot;Success&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">ResponseCode</span><span style="color: #0000ff">&gt;</span>NoError<span style="color: #0000ff">&lt;/</span><span style="color: #800000">ResponseCode</span><span style="color: #0000ff">&gt;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span> - <span style="color: #0000ff">&lt;</span><span style="color: #800000">m:MailTips</span> <span style="color: #ff0000">xmlns:m</span><span style="color: #0000ff">=&quot;https://schemas.microsoft.com/exchange/services/2006/messages&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060">  13:</span> - <span style="color: #0000ff">&lt;</span><span style="color: #800000">t:RecipientAddress</span> <span style="color: #ff0000">xmlns:t</span><span style="color: #0000ff">=&quot;https://schemas.microsoft.com/exchange/services/2006/types&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">t:Name</span> <span style="color: #0000ff">/&gt;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060">  15:</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">t:EmailAddress</span><span style="color: #0000ff">&gt;</span>user2@contoso.com<span style="color: #0000ff">&lt;/</span><span style="color: #800000">t:EmailAddress</span><span style="color: #0000ff">&gt;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060">  16:</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">t:RoutingType</span><span style="color: #0000ff">&gt;</span>SMTP<span style="color: #0000ff">&lt;/</span><span style="color: #800000">t:RoutingType</span><span style="color: #0000ff">&gt;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060">  17:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">t:RecipientAddress</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum18" style="color: #606060">  18:</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">t:PendingMailTips</span> <span style="color: #ff0000">xmlns:t</span><span style="color: #0000ff">=&quot;https://schemas.microsoft.com/exchange/services/2006/types&quot;</span> <span style="color: #0000ff">/&gt;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum19" style="color: #606060">  19:</span> - <span style="color: #0000ff">&lt;</span><span style="color: #800000">t:OutOfOffice</span> <span style="color: #ff0000">xmlns:t</span><span style="color: #0000ff">=&quot;https://schemas.microsoft.com/exchange/services/2006/types&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum20" style="color: #606060">  20:</span> - <span style="color: #0000ff">&lt;</span><span style="color: #800000">t:ReplyBody</span> <span style="color: #ff0000">xml:lang</span><span style="color: #0000ff">=&quot;en-us&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum21" style="color: #606060">  21:</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">t:Message</span><span style="color: #0000ff">&gt;</span> I am Out of Office Today<span style="color: #0000ff">&lt;/</span><span style="color: #800000">t:Message</span><span style="color: #0000ff">&gt;</span> </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum22" style="color: #606060">  22:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">t:ReplyBody</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum23" style="color: #606060">  23:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">t:OutOfOffice</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum24" style="color: #606060">  24:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">m:MailTips</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum25" style="color: #606060">  25:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">MailTipsResponseMessageType</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum26" style="color: #606060">  26:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ResponseMessages</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum27" style="color: #606060">  27:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">GetMailTipsResponse</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum28" style="color: #606060">  28:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">s:Body</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum29" style="color: #606060">  29:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">s:Envelope</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF--></div>
</div>

<p>Though the <strong>GetMailTips operation</strong> is <strong>NOT</strong> yet available with <strong>EWS Managed API</strong>, with the above sample using <strong>raw HTTP EWS SOAP request</strong> we can easily retrieve the required information. For more details, refer the following articles: 

  <br />

  <br /></p>

<ul>
  <li><strong>GetMailTips Operation 
      <br /></strong><a href="https://msdn.microsoft.com/en-us/library/exchange/dd877060(v=exchg.150).aspx">https://msdn.microsoft.com/en-us/library/exchange/dd877060(v=exchg.150).aspx</a> </li>

  <li><strong>MailTipsRequested 
      <br /></strong><a href="https://msdn.microsoft.com/en-us/library/exchange/dd899452(v=exchg.150).aspx">https://msdn.microsoft.com/en-us/library/exchange/dd899452(v=exchg.150).aspx</a> </li>
</ul>]]></content:encoded>
    </item>
  </channel>
</rss>