<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7123450</id><updated>2012-01-30T21:30:42.827+11:00</updated><category term='calendar'/><category term='Powershell'/><category term='Exchange'/><category term='Message Tracking'/><category term='Exchange 2010 SP2'/><category term='SendAS'/><category term='Tech-ed'/><category term='Office365'/><category term='Exchange 2007'/><category term='EMS'/><category term='Classifications'/><category term='Quarantined'/><category term='c#'/><category term='Module'/><category term='WSDL'/><category term='Exchange Web Services'/><category term='Australia'/><category term='archive'/><category term='EWS Managed API'/><category term='WMI'/><category term='oab'/><category term='ADSI'/><category term='Logs'/><category term='rss'/><category term='Exchange Online'/><category term='outlookanywhere'/><category term='Exchange 2003'/><category term='Exmerge'/><category term='Transport Agent'/><category term='Syncronization'/><category term='Gui'/><category term='Exchange 2010 SP1'/><category term='VBS'/><category term='CDO 1.2'/><category term='Office 365'/><category term='GAL'/><category term='EWS Module'/><category term='AntiSpam'/><category term='OWA'/><category term='Outlook 2010'/><category term='cdoex'/><category term='Unified messaging'/><category term='WebDAV'/><category term='Contacts'/><category term='EWS'/><category term='Search'/><category term='Registry'/><category term='ewsUtil'/><category term='OOF'/><category term='public folders'/><category term='ExchangeOnline'/><category term='permissions'/><category term='autodiscover'/><category term='RDO'/><category term='iPhone'/><category term='Mailbox Size'/><category term='Active Directory'/><category term='twitter'/><category term='Outlook 2007'/><category term='Exchange 2010'/><category term='Junk Email'/><category term='Audit'/><category term='PST'/><title type='text'>Glen's Exchange Dev Blog</title><subtitle type='html'>Pushing the Envelope in Messaging Development</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default?start-index=101&amp;max-results=100'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>328</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7123450.post-2498320325266676587</id><published>2012-01-25T21:38:00.000+11:00</published><updated>2012-01-25T21:53:26.273+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Online'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='WSDL'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS'/><title type='text'>401 errors in Exchange Online using EWS WSDL proxy code and raw HTML</title><content type='html'>&lt;br /&gt;If your developing EWS code against Exchange Online or possibly another large load balanced Hosted Exchange system you may find that a lot of the sample code you see on MSDN or other places that uses EWS Proxy code will always return 401 errors when you try to use it against Exchange Online (The Managed API isn't affected) eg a standard example is something like &lt;a href="http://msdn.microsoft.com/en-us/library/bb408524%28v=EXCHG.140%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb408524%28v=EXCHG.140%29.aspx&lt;/a&gt;. What can cause this problem is the failure to process the exchangecookie in an appropriate way. There is description of what the exchangecookie is used for on &lt;a href="http://blogs.msdn.com/b/exchangedev/archive/2011/07/20/client-access-server-affinity-and-network-load-balancing-considerations-for-programmatic-access-to-exchange-online.aspx"&gt;http://blogs.msdn.com/b/exchangedev/archive/2011/07/20/client-access-server-affinity-and-network-load-balancing-considerations-for-programmatic-access-to-exchange-online.aspx&lt;/a&gt; . Although this says nothing about Authentication if the request object your using be its a SOAP proxy or HttpwebRequest doesn't have the cookiecontainer initialized (which by default they don't) before you submit the first request you'll get a 401. So&amp;nbsp; basically if you have a normal EWS sample after you set the URL or Credentials make sure you initialize the cookie container.eg.&lt;br /&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;esb.Url = &lt;span style="color: #a31515;"&gt;"https://CAS01.contoso.com/EWS/exchange.asmx"&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;esb..CookieContainer = new CookieContainer();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If your using Raw HTML and a HttpWebRequest make sure you do the same thing before submitting the first request.&lt;br /&gt;&lt;br /&gt;A code sample is worth a 1000 words so here's a basic Exchange Online/Office365 Autodiscover and WDSL proxy sample that just does a simple GetFolder to the Inbox.&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-c" start="1"&gt;&lt;li class="alt"&gt;String&amp;nbsp;MbMailbox&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"user@domain.onmicrosoft.com"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;String&amp;nbsp;AutoDiscoURL&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;NetworkCredential&amp;nbsp;ncCred&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;NetworkCredential(&lt;span class="string"&gt;"user@domain.onmicrosoft.com"&lt;/span&gt;,&lt;span class="string"&gt;"password"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;String&amp;nbsp;EWSURL&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;null&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;String&amp;nbsp;auDisXML&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;Autodiscover&amp;nbsp;xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\"&amp;gt;&amp;lt;Request&amp;gt;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;EMailAddress&amp;gt;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;MbMailbox&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/EMailAddress&amp;gt;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;AcceptableResponseSchema&amp;gt;http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a&amp;lt;/AcceptableResponseSchema&amp;gt;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/Request&amp;gt;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/Autodiscover&amp;gt;"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;System.Net.HttpWebRequest&amp;nbsp;adAutoDiscoRequest&amp;nbsp;=&amp;nbsp;(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(AutoDiscoURL);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="keyword"&gt;byte&lt;/span&gt;[]&amp;nbsp;bytes&amp;nbsp;=&amp;nbsp;Encoding.UTF8.GetBytes(auDisXML);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;adAutoDiscoRequest.ContentLength&amp;nbsp;=&amp;nbsp;bytes.Length;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;adAutoDiscoRequest.ContentType&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"text/xml"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;adAutoDiscoRequest.Headers.Add(&lt;span class="string"&gt;"Translate"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"F"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;adAutoDiscoRequest.Method&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"POST"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;adAutoDiscoRequest.Credentials&amp;nbsp;=&amp;nbsp;ncCred;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;Stream&amp;nbsp;rsRequestStream&amp;nbsp;=&amp;nbsp;adAutoDiscoRequest.GetRequestStream();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;rsRequestStream.Write(bytes,&amp;nbsp;0,&amp;nbsp;bytes.Length);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;rsRequestStream.Close();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;adAutoDiscoRequest.AllowAutoRedirect&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;false&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;WebResponse&amp;nbsp;adResponse&amp;nbsp;=&amp;nbsp;adAutoDiscoRequest.GetResponse();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;String&amp;nbsp;Redirect&amp;nbsp;=&amp;nbsp;adResponse.Headers.Get(&lt;span class="string"&gt;"Location"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(Redirect&amp;nbsp;!=&amp;nbsp;&lt;span class="keyword"&gt;null&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;adAutoDiscoRequest&amp;nbsp;=&amp;nbsp;(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(Redirect);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;adAutoDiscoRequest.ContentLength&amp;nbsp;=&amp;nbsp;bytes.Length;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;adAutoDiscoRequest.ContentType&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"text/xml"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;adAutoDiscoRequest.Headers.Add(&lt;span class="string"&gt;"Translate"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"F"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;adAutoDiscoRequest.Method&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"POST"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;adAutoDiscoRequest.Credentials&amp;nbsp;=&amp;nbsp;ncCred;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rsRequestStream&amp;nbsp;=&amp;nbsp;adAutoDiscoRequest.GetRequestStream();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;rsRequestStream.Write(bytes,&amp;nbsp;0,&amp;nbsp;bytes.Length);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;rsRequestStream.Close();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;adResponse&amp;nbsp;=&amp;nbsp;adAutoDiscoRequest.GetResponse();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;Stream&amp;nbsp;rsResponseStream&amp;nbsp;=&amp;nbsp;adResponse.GetResponseStream();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;XmlDocument&amp;nbsp;reResponseDoc&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;XmlDocument();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;reResponseDoc.Load(rsResponseStream);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;XmlNodeList&amp;nbsp;pfProtocolNodes&amp;nbsp;=&amp;nbsp;reResponseDoc.GetElementsByTagName(&lt;span class="string"&gt;"Protocol"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="keyword"&gt;foreach&lt;/span&gt;&amp;nbsp;(XmlNode&amp;nbsp;xnNode&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;pfProtocolNodes)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;XmlNodeList&amp;nbsp;adChildNodes&amp;nbsp;=&amp;nbsp;xnNode.ChildNodes;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;foreach&lt;/span&gt;&amp;nbsp;(XmlNode&amp;nbsp;xnSubChild&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;adChildNodes)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;switch&lt;/span&gt;&amp;nbsp;(xnSubChild.Name)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;case&lt;/span&gt;&amp;nbsp;&lt;span class="string"&gt;"EwsUrl"&lt;/span&gt;:&amp;nbsp;EWSURL&amp;nbsp;=&amp;nbsp;xnSubChild.InnerText;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;break&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;ExchangeServiceBinding&amp;nbsp;esExchangeServiceBinding&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;ExchangeServiceBinding();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;esExchangeServiceBinding.Credentials&amp;nbsp;=&amp;nbsp;ncCred;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;esExchangeServiceBinding.Url&amp;nbsp;=&amp;nbsp;EWSURL;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;esExchangeServiceBinding.CookieContainer&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;CookieContainer();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;DistinguishedFolderIdType[]&amp;nbsp;dsFolderid&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;DistinguishedFolderIdType[1];&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;dsFolderid[0]&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;DistinguishedFolderIdType();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;dsFolderid[0].Id&amp;nbsp;=&amp;nbsp;DistinguishedFolderIdNameType.inbox;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;GetFolderType&amp;nbsp;gfFolderType&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;GetFolderType();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;gfFolderType.FolderIds&amp;nbsp;=&amp;nbsp;dsFolderid;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;gfFolderType.FolderShape&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;FolderResponseShapeType();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;gfFolderType.FolderShape.BaseShape&amp;nbsp;=&amp;nbsp;DefaultShapeNamesType.Default;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;GetFolderResponseType&amp;nbsp;gfGetFolderResponse&amp;nbsp;=&amp;nbsp;esExchangeServiceBinding.GetFolder(gfFolderType);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(gfGetFolderResponse.ResponseMessages.Items[0].ResponseClass&amp;nbsp;==&amp;nbsp;ResponseClassType.Success)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FolderType&amp;nbsp;Folder&amp;nbsp;=&amp;nbsp;(FolderType)((FolderInfoResponseMessageType)gfGetFolderResponse.ResponseMessages.Items[0]).Folders[0];&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.WriteLine(Folder.DisplayName);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-2498320325266676587?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/2498320325266676587/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=2498320325266676587' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/2498320325266676587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/2498320325266676587'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2012/01/401-erors-in-exchange-online-using-ews.html' title='401 errors in Exchange Online using EWS WSDL proxy code and raw HTML'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-6283936843597359353</id><published>2012-01-23T17:27:00.000+11:00</published><updated>2012-01-30T21:30:43.024+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>EWS Managed API and Powershell How-To series Part 2 - Folders</title><content type='html'>This is Part2 in my continuing EWS Managed API and Powershell how to series, in this post im going to look at using Mailbox Folders in Exchange Web Services. When you look at mailboxes from a structured content point of view the most obvious data structure is the folders within it. Dealing with these structures can provide a number of challenges which I'll go through. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Binding to and Accessing a Folder&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;To access a folder using EWS you must first know its folderId which from a useability perspective presents most people with a bit of a challenge. eg you may know the path to the folder you want to access is \Inbox\Subfolder but the FolderID itself is a large Base64 Enocded value.For all the standard folders in a mailbox such as the Calendar, Contacts, Inbox, SentItems folders there is a WellKnownFolderName enumeration that makes things easy eg so this basically provides you with a very easy way to bind to the Inbox, Calendar etc. For example to bind to the Inbox folder &lt;br /&gt;&lt;br /&gt;&amp;nbsp;$folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,"user@mailbox.com")&amp;nbsp; &lt;br /&gt;$Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)&lt;br /&gt;&lt;br /&gt;If your dealing with a folder outside of the WellKnownFolderName enumeration then you need to search and find the folder in question. There are a couple of ways you could do that one would be to use a DeepTraversal of all the folders in the Mailbox and then filter the results. The method I like to use is to split the search path and then do a Shallow traversal search of all the folders in the path eg&lt;br /&gt;&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;##&amp;nbsp;Find&amp;nbsp;and&amp;nbsp;Bind&amp;nbsp;to&amp;nbsp;Folder&amp;nbsp;based&amp;nbsp;on&amp;nbsp;Path&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#Define&amp;nbsp;the&amp;nbsp;path&amp;nbsp;to&amp;nbsp;search&amp;nbsp;should&amp;nbsp;be&amp;nbsp;seperated&amp;nbsp;with&amp;nbsp;\&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$PathToSearch&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"\Inbox\Blah"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#Bind&amp;nbsp;to&amp;nbsp;the&amp;nbsp;MSGFolder&amp;nbsp;Root&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$folderid&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,&lt;span class="string"&gt;"user@domain.com"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$tfTargetFolder&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.Folder]::Bind(&lt;span class="variable"&gt;$service&lt;/span&gt;,&lt;span class="variable"&gt;$folderid&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Split&amp;nbsp;the&amp;nbsp;Search&amp;nbsp;path&amp;nbsp;into&amp;nbsp;an&amp;nbsp;array&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fldArray&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$PathToSearch&lt;/span&gt;.Split(&lt;span class="string"&gt;"\")&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;#Loop&amp;nbsp;through&amp;nbsp;the&amp;nbsp;Split&amp;nbsp;Array&amp;nbsp;and&amp;nbsp;do&amp;nbsp;a&amp;nbsp;Search&amp;nbsp;for&amp;nbsp;each&amp;nbsp;level&amp;nbsp;of&amp;nbsp;folder&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;for&amp;nbsp;($lint&amp;nbsp;=&amp;nbsp;1;&amp;nbsp;$lint&amp;nbsp;-lt&amp;nbsp;$fldArray.Length;&amp;nbsp;$lint++)&amp;nbsp;{&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$fldArray[$lint]&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#Perform&amp;nbsp;search&amp;nbsp;based&amp;nbsp;on&amp;nbsp;the&amp;nbsp;displayname&amp;nbsp;of&amp;nbsp;each&amp;nbsp;folder&amp;nbsp;level&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$fvFolderView&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderView(1)&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$SfSearchFilter&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$fldArray[$lint])&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$findFolderResults&amp;nbsp;=&amp;nbsp;$service.FindFolders($tfTargetFolder.Id,$SfSearchFilter,$fvFolderView)&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;($findFolderResults.TotalCount&amp;nbsp;-gt&amp;nbsp;0){&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach($folder&amp;nbsp;in&amp;nbsp;$findFolderResults.Folders){&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$tfTargetFolder&amp;nbsp;=&amp;nbsp;$folder&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else{&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"&lt;/span&gt;Error&amp;nbsp;Folder&amp;nbsp;Not&amp;nbsp;Found"&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$tfTargetFolder&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$tfTargetFolder&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;The Tale of Two Folder Roots &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;If you have ever looked at a mailbox in a Mapi Editor like MFCMapi or OutlookSpy you know there are actually two different Folder Roots in a Mailbox the IPM_Subtree (represented by the "Top of the Information Store" in the below image) which is what the user sees in Outlook in their Folder Tree and the Non_IPM_Subtree which is the level above the IPM_Subtree where a lot of the Meta-Information for a mailbox gets stored (represented by the "Root Container" in the below image) &lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-7iMazCsaGSQ/TxZlesIGUCI/AAAAAAAAADU/UlIuimdX7rw/s1600/Capture88.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-7iMazCsaGSQ/TxZlesIGUCI/AAAAAAAAADU/UlIuimdX7rw/s320/Capture88.PNG" width="316" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;When you look at the WellKnowFolderName enum the Non_IPM_Subtree is&lt;br /&gt;&lt;br /&gt;[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root&lt;br /&gt;&lt;br /&gt;and the IPM_Subtree is&lt;br /&gt;&lt;br /&gt;[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot&lt;br /&gt;&lt;br /&gt;This becomes import when you want to look at getting and modifying Mailbox configuration information also if your are trying to calculate the total mailbox size you need to make sure you include these folders in your calculation.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Properties on a Folder &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;When you Bind to a folder in EWS the standard folder properties provided by the Strongly typed Folder class are returned. This is good but you may find that a lot of the properties that you really want to access for example things like the FolderSize or the FolderPath aren't returned. To Access these you need to make use of the Extended properties on the Folder which allows you to access any of the underlying (Exchange/Mapi) properties of that folder object.. To use an Extended property you first need to define the particular property you want to access (as always i recommend you use a Mapi editor to work out what the Tag,Datatype of the property is you want to access a good), add that property to a PropertySet and then tell EWS to load those properties when ether you bind to the folder, search for the folder or use the Load Method.Some Extended properties that are usefull on Folders are&lt;br /&gt;&lt;br /&gt;The PR_Folder_PathName property returns the fullpath to a folder that is delimited by the &lt;a href="http://en.wikipedia.org/wiki/Byte_order_mark"&gt;byte order mark&lt;/a&gt; FE-FF so if you want to return a \ delimited path you need to replace these values in the Unicode string that is returned when you retrieve this property.&lt;br /&gt;&lt;br /&gt;&lt;span class="variable"&gt;The PR_MESSAGE_SIZE_EXTENDED&lt;/span&gt; property is a 64 Bit Integer that represents the size of the all Items in the Folder&lt;br /&gt;&lt;br /&gt;PR_Folder_Type is a Interger property that tells you what type of folder this is which is useful if you want to tell if a folder is a SearchFolder &lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Enumerating all Folders in a Mailbox&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;One common building block of scripts is the ability to enumerate ever folder in a Mailbox which can be achieved using the FindFolders Operation in EWS with a DeepTraversal Scope. If the mailbox your enumerating has more then 1000 folders you need to take throttling into account in 2010. Here's an example that gets all the folders in a Mailbox deal with throttling and also show how to use the Extended Properties I mentioned above.&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Define&amp;nbsp;Function&amp;nbsp;to&amp;nbsp;convert&amp;nbsp;String&amp;nbsp;to&amp;nbsp;FolderPath&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="keyword"&gt;function&lt;/span&gt;&amp;nbsp;ConvertToString(&lt;span class="variable"&gt;$ipInputString&lt;/span&gt;){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Val1Text&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;""&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;for&lt;/span&gt;&amp;nbsp;(&lt;span class="variable"&gt;$clInt&lt;/span&gt;=0;&lt;span class="variable"&gt;$clInt&lt;/span&gt;&amp;nbsp;-lt&amp;nbsp;&lt;span class="variable"&gt;$ipInputString&lt;/span&gt;.length;&lt;span class="variable"&gt;$clInt&lt;/span&gt;++){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Val1Text&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$Val1Text&lt;/span&gt;&amp;nbsp;+&amp;nbsp;[Convert]::ToString([Convert]::ToChar([Convert]::ToInt32(&lt;span class="variable"&gt;$ipInputString&lt;/span&gt;.Substring(&lt;span class="variable"&gt;$clInt&lt;/span&gt;,2),16)))&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$clInt&lt;/span&gt;++&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt;&amp;nbsp;&lt;span class="variable"&gt;$Val1Text&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#Define&amp;nbsp;Mailbox&amp;nbsp;to&amp;nbsp;access&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"glen@mymailbox.domain.com"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;"Checking&amp;nbsp;:&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#Define&amp;nbsp;Extended&amp;nbsp;properties&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$PR_FOLDER_TYPE&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(13825,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$folderidcnt&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Define&amp;nbsp;the&amp;nbsp;FolderView&amp;nbsp;used&amp;nbsp;for&amp;nbsp;Export&amp;nbsp;should&amp;nbsp;not&amp;nbsp;be&amp;nbsp;any&amp;nbsp;larger&amp;nbsp;then&amp;nbsp;1000&amp;nbsp;folders&amp;nbsp;due&amp;nbsp;to&amp;nbsp;throttling&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderView(1000)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Deep&amp;nbsp;Transval&amp;nbsp;will&amp;nbsp;ensure&amp;nbsp;all&amp;nbsp;folders&amp;nbsp;in&amp;nbsp;the&amp;nbsp;search&amp;nbsp;path&amp;nbsp;are&amp;nbsp;returned&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;.Traversal&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$psPropertySet&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$PR_MESSAGE_SIZE_EXTENDED&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3592,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Long);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$PR_DELETED_MESSAGE_SIZE_EXTENDED&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26267,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Long);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$PR_Folder_Path&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26293,&amp;nbsp;[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Add&amp;nbsp;Properties&amp;nbsp;to&amp;nbsp;the&amp;nbsp;&amp;nbsp;Property&amp;nbsp;Set&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$psPropertySet&lt;/span&gt;.Add(&lt;span class="variable"&gt;$PR_MESSAGE_SIZE_EXTENDED&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$psPropertySet&lt;/span&gt;.Add(&lt;span class="variable"&gt;$PR_Folder_Path&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;.PropertySet&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$psPropertySet&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#The&amp;nbsp;Search&amp;nbsp;filter&amp;nbsp;will&amp;nbsp;exclude&amp;nbsp;any&amp;nbsp;Search&amp;nbsp;Folders&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$sfSearchFilter&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo(&lt;span class="variable"&gt;$PR_FOLDER_TYPE&lt;/span&gt;,&lt;span class="string"&gt;"1"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#The&amp;nbsp;Do&amp;nbsp;loop&amp;nbsp;will&amp;nbsp;handle&amp;nbsp;any&amp;nbsp;paging&amp;nbsp;that&amp;nbsp;is&amp;nbsp;required&amp;nbsp;if&amp;nbsp;there&amp;nbsp;are&amp;nbsp;more&amp;nbsp;the&amp;nbsp;1000&amp;nbsp;folders&amp;nbsp;in&amp;nbsp;a&amp;nbsp;mailbox&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;do&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$Service&lt;/span&gt;.FindFolders(&lt;span class="variable"&gt;$folderidcnt&lt;/span&gt;,&lt;span class="variable"&gt;$sfSearchFilter&lt;/span&gt;,&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;foreach&lt;/span&gt;(&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;.Folders){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"Processing&amp;nbsp;:&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;.displayName&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$TotalItemCount&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$TotalItemCount&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;.TotalCount;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$FolderSize&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$FolderSizeValue&lt;/span&gt;&amp;nbsp;=&amp;nbsp;0&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment"&gt;#Try&amp;nbsp;to&amp;nbsp;Get&amp;nbsp;the&amp;nbsp;FolderSize&amp;nbsp;Value&amp;nbsp;and&amp;nbsp;output&amp;nbsp;it&amp;nbsp;to&amp;nbsp;the&amp;nbsp;$FolderSize&amp;nbsp;varible&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;.TryGetProperty(&lt;span class="variable"&gt;$PR_MESSAGE_SIZE_EXTENDED&lt;/span&gt;,[ref]&amp;nbsp;&lt;span class="variable"&gt;$FolderSize&lt;/span&gt;))&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$FolderSizeValue&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Int64]&lt;span class="variable"&gt;$FolderSize&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$foldpathval&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment"&gt;#Try&amp;nbsp;to&amp;nbsp;get&amp;nbsp;the&amp;nbsp;FolderPath&amp;nbsp;Value&amp;nbsp;and&amp;nbsp;then&amp;nbsp;covert&amp;nbsp;it&amp;nbsp;to&amp;nbsp;a&amp;nbsp;usable&amp;nbsp;String&amp;nbsp;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;.TryGetProperty(&lt;span class="variable"&gt;$PR_Folder_Path&lt;/span&gt;,[ref]&amp;nbsp;&lt;span class="variable"&gt;$foldpathval&lt;/span&gt;))&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$binarry&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Text.Encoding]::UTF8.GetBytes(&lt;span class="variable"&gt;$foldpathval&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$hexArr&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$binarry&lt;/span&gt;&amp;nbsp;|&amp;nbsp;&lt;span class="builtin"&gt;ForEach-Object&lt;/span&gt;&amp;nbsp;{&amp;nbsp;&lt;span class="variable"&gt;$_&lt;/span&gt;.ToString(&lt;span class="string"&gt;"X2"&lt;/span&gt;)&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$hexString&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$hexArr&lt;/span&gt;&amp;nbsp;-join&amp;nbsp;&lt;span class="string"&gt;''&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$hexString&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$hexString&lt;/span&gt;.Replace(&lt;span class="string"&gt;"FEFF"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"5C00"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$fpath&lt;/span&gt;&amp;nbsp;=&amp;nbsp;ConvertToString(&lt;span class="variable"&gt;$hexString&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"FolderPath&amp;nbsp;:&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$fpath&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"FolderSize&amp;nbsp;:&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$FolderSizeValue&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&lt;span class="keyword"&gt;while&lt;/span&gt;(&lt;span class="variable"&gt;$fiResult&lt;/span&gt;.MoreAvailable&amp;nbsp;-eq&amp;nbsp;&lt;span class="variable"&gt;$true&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Creating Folders&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;After all the other stuff I've just covered creating folders is actually quite simple eg to create a subfolder under the Inbox folder all you need is&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Define&amp;nbsp;Mailbox&amp;nbsp;to&amp;nbsp;access&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"glen@mailbox.domain.com"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;##&amp;nbsp;Bind&amp;nbsp;to&amp;nbsp;the&amp;nbsp;Inbox&amp;nbsp;Sample&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$folderid&lt;/span&gt;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Inbox&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.Folder]::Bind(&lt;span class="variable"&gt;$service&lt;/span&gt;,&lt;span class="variable"&gt;$folderid&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$NewFolder&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.Folder(&lt;span class="variable"&gt;$service&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$NewFolder&lt;/span&gt;.DisplayName&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"My&amp;nbsp;New&amp;nbsp;Folder123"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$NewFolder&lt;/span&gt;.Save(&lt;span class="variable"&gt;$Inbox&lt;/span&gt;.Id)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&amp;nbsp;To Check if a folder already exists before doing so you need to first do a search for the existing folder here's how you can do that&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Define&amp;nbsp;Folder&amp;nbsp;Name&amp;nbsp;to&amp;nbsp;Search&amp;nbsp;for&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$FolderName&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"My&amp;nbsp;New&amp;nbsp;Folder123"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Define&amp;nbsp;Folder&amp;nbsp;Veiw&amp;nbsp;Really&amp;nbsp;only&amp;nbsp;want&amp;nbsp;to&amp;nbsp;return&amp;nbsp;one&amp;nbsp;object&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderView(1)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Define&amp;nbsp;a&amp;nbsp;Search&amp;nbsp;folder&amp;nbsp;that&amp;nbsp;is&amp;nbsp;going&amp;nbsp;to&amp;nbsp;do&amp;nbsp;a&amp;nbsp;search&amp;nbsp;based&amp;nbsp;on&amp;nbsp;the&amp;nbsp;DisplayName&amp;nbsp;of&amp;nbsp;the&amp;nbsp;folder&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$SfSearchFilter&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,&lt;span class="variable"&gt;$FolderName&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Do&amp;nbsp;the&amp;nbsp;Search&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$findFolderResults&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$service&lt;/span&gt;.FindFolders(&lt;span class="variable"&gt;$Inbox&lt;/span&gt;.Id,&lt;span class="variable"&gt;$SfSearchFilter&lt;/span&gt;,&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span class="variable"&gt;$findFolderResults&lt;/span&gt;.TotalCount&amp;nbsp;-eq&amp;nbsp;0){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"Folder&amp;nbsp;Doesn't&amp;nbsp;Exist"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="keyword"&gt;else&lt;/span&gt;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"Folder&amp;nbsp;Exist"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;b&gt; &lt;/b&gt;&lt;br /&gt;&lt;b&gt;Deleting a Folder&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Deleting a folder is rather simple all you really need to do is call the delete Method but lets look at a more complicated sample. Given the above sample of creating a folder under the Inbox folder lets look at something that first binds to that folder which would have a path of "\Inbox\My New Folder123" and then deletes it.&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;##&amp;nbsp;Find&amp;nbsp;and&amp;nbsp;Bind&amp;nbsp;to&amp;nbsp;Folder&amp;nbsp;based&amp;nbsp;on&amp;nbsp;Path&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#Define&amp;nbsp;the&amp;nbsp;path&amp;nbsp;to&amp;nbsp;search&amp;nbsp;should&amp;nbsp;be&amp;nbsp;seperated&amp;nbsp;with&amp;nbsp;\&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$PathToSearch&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"\Inbox\My&amp;nbsp;New&amp;nbsp;Folder123"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#Bind&amp;nbsp;to&amp;nbsp;the&amp;nbsp;MSGFolder&amp;nbsp;Root&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$folderid&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$tfTargetFolder&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.Folder]::Bind(&lt;span class="variable"&gt;$service&lt;/span&gt;,&lt;span class="variable"&gt;$folderid&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Split&amp;nbsp;the&amp;nbsp;Search&amp;nbsp;path&amp;nbsp;into&amp;nbsp;an&amp;nbsp;array&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fldArray&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$PathToSearch&lt;/span&gt;.Split(&lt;span class="string"&gt;"\")&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;#Loop&amp;nbsp;through&amp;nbsp;the&amp;nbsp;Split&amp;nbsp;Array&amp;nbsp;and&amp;nbsp;do&amp;nbsp;a&amp;nbsp;Search&amp;nbsp;for&amp;nbsp;each&amp;nbsp;level&amp;nbsp;of&amp;nbsp;folder&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;for&amp;nbsp;($lint&amp;nbsp;=&amp;nbsp;1;&amp;nbsp;$lint&amp;nbsp;-lt&amp;nbsp;$fldArray.Length;&amp;nbsp;$lint++)&amp;nbsp;{&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$fldArray[$lint]&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#Perform&amp;nbsp;search&amp;nbsp;based&amp;nbsp;on&amp;nbsp;the&amp;nbsp;displayname&amp;nbsp;of&amp;nbsp;each&amp;nbsp;folder&amp;nbsp;level&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$fvFolderView&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderView(1)&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$SfSearchFilter&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$fldArray[$lint])&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$findFolderResults&amp;nbsp;=&amp;nbsp;$service.FindFolders($tfTargetFolder.Id,$SfSearchFilter,$fvFolderView)&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;($findFolderResults.TotalCount&amp;nbsp;-gt&amp;nbsp;0){&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach($folder&amp;nbsp;in&amp;nbsp;$findFolderResults.Folders){&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$tfTargetFolder&amp;nbsp;=&amp;nbsp;$folder&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else{&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"&lt;/span&gt;Error&amp;nbsp;Folder&amp;nbsp;Not&amp;nbsp;Found&lt;span class="string"&gt;"&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$tfTargetFolder&amp;nbsp;=&amp;nbsp;$null&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;if($tfTargetFolder&amp;nbsp;-ne&amp;nbsp;$null){&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#Delete&amp;nbsp;the&amp;nbsp;Folder&amp;nbsp;using&amp;nbsp;HardDelete&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$tfTargetFolder.Delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::HardDelete)&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"&lt;/span&gt;Folder&amp;nbsp;Deleted"&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;b&gt;Emptying or Deleting old items from a folder&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;In Exchange 2010 you can use the Empty&amp;nbsp; Method to empty all the Items from a folder (or essentially delete all the Items from a folder a once). The is pretty easy to do for example to delete all the Items in the Inbox and all subfolders you can use &lt;br /&gt;&lt;br /&gt;$Inbox.Empty([Microsoft.Exchange.WebServices.Data.DeleteMode]::HardDelete, $true);&lt;br /&gt;&lt;br /&gt;If your using 2007 or you want to delete Items in the Calendar folder you need to select the Items first and do a batch delete. For example to Clean all the Items in the Calendar folder&lt;br /&gt;&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#&amp;nbsp;Bind&amp;nbsp;to&amp;nbsp;the&amp;nbsp;Calendar&amp;nbsp;folder&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$folderid&lt;/span&gt;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Calendar&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.Folder]::Bind(&lt;span class="variable"&gt;$service&lt;/span&gt;,&lt;span class="variable"&gt;$folderid&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#Set&amp;nbsp;Itemview&amp;nbsp;to&amp;nbsp;1000&amp;nbsp;to&amp;nbsp;deal&amp;nbsp;with&amp;nbsp;throttling&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$ivItemView&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.ItemView(1000)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;""&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;do{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$Calendar&lt;/span&gt;.FindItems(&lt;span class="variable"&gt;$ivItemView&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment"&gt;#Define&amp;nbsp;ItemIds&amp;nbsp;collection&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Itemids&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[activator]:&lt;span class="symbol"&gt;:createinstance&lt;/span&gt;(([type]&lt;span class="string"&gt;'System.Collections.Generic.List`1'&lt;/span&gt;).makegenerictype([Microsoft.Exchange.WebServices.Data.ItemId]))&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"Delete&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;.Items.Count&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;nbsp;Items"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;foreach&lt;/span&gt;(&lt;span class="variable"&gt;$Item&lt;/span&gt;&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;.Items){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Itemids&lt;/span&gt;.Add(&lt;span class="variable"&gt;$Item&lt;/span&gt;.Id)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment"&gt;#Delete&amp;nbsp;the&amp;nbsp;Items&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Result&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$service&lt;/span&gt;.DeleteItems(&lt;span class="variable"&gt;$Itemids&lt;/span&gt;,[Microsoft.Exchange.WebServices.Data.DeleteMode]::SoftDelete,[Microsoft.Exchange.WebServices.Data.SendCancellationsMode]::SendToNone,[Microsoft.Exchange.WebServices.Data.AffectedTaskOccurrence]::AllOccurrences)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[INT]&lt;span class="variable"&gt;$Rcount&lt;/span&gt;&amp;nbsp;=&amp;nbsp;0&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;foreach&lt;/span&gt;&amp;nbsp;(&lt;span class="variable"&gt;$res&lt;/span&gt;&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class="variable"&gt;$Result&lt;/span&gt;){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span class="variable"&gt;$res&lt;/span&gt;.Result&amp;nbsp;-eq&amp;nbsp;[Microsoft.Exchange.WebServices.Data.ServiceResult]::Success){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Rcount&lt;/span&gt;++&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Rcount&lt;/span&gt;.ToString()&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;nbsp;Items&amp;nbsp;deleted&amp;nbsp;successfully"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$ivItemView&lt;/span&gt;.offset&amp;nbsp;+=&amp;nbsp;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;.Items.Count&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&lt;span class="keyword"&gt;while&lt;/span&gt;(&lt;span class="variable"&gt;$fiResult&lt;/span&gt;.MoreAvailable&amp;nbsp;-eq&amp;nbsp;&lt;span class="variable"&gt;$true&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;b&gt;Search Folders&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;A search folder is like a regular mailbox folder, except that it contains only links to messages in other folders that meet the criteria set in the search filter restriction which means that search folders are great for nonchanging, nondynamic queries. Search folders like Search Filters make use of restrictions in Exchange rather then using the Content Index which means that this comes along with some compromises ,if you are going to use search folders (or a lot of search filters) defiantly have a read of&amp;nbsp; &lt;a href="http://technet.microsoft.com/en-us/library/cc535025%28EXCHG.80%29.aspx"&gt;http://technet.microsoft.com/en-us/library/cc535025%28EXCHG.80%29.aspx&lt;/a&gt; .&lt;br /&gt;&lt;br /&gt;To tell if a folder is a search folder the extended property PR_Folder_Type&amp;nbsp; is useful if the PR_Folder_Type is set to 2 then this indicates its a search folder.&lt;br /&gt;&lt;br /&gt;For an example of creating a search folder have a look at &lt;a href="http://gsexdev.blogspot.com/2011/09/create-search-folder-using-ews-managed.html"&gt;http://gsexdev.blogspot.com/2011/09/create-search-folder-using-ews-managed.html&amp;nbsp;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For an example of finding and binding to the AllItems search folder in Exchange 2010 see &lt;br /&gt;&lt;br /&gt;&lt;a href="http://gsexdev.blogspot.com/2011/08/using-allitems-search-folder-from.html"&gt;http://gsexdev.blogspot.com/2011/08/using-allitems-search-folder-from.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To find and delete a search folder see &lt;a href="http://tst.social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/426a37c8-f1dd-4438-a081-e2b0e378bc5a"&gt;http://tst.social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/426a37c8-f1dd-4438-a081-e2b0e378bc5a&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Public Folders&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;When thinking about public folders its useful to consider them similar to a mailbox however unlike mailboxes you can't do a Deep Traversal of Public folders so when trying to access a public folder you need to either do a shallow traversal search for each folder level eg using a script similar to what i posted above. The other method of accessing a public folder directly is to use the Exchange Management Shell cmdlets and cover the HexEntryID you can get with the EMS to the EwsID.&amp;nbsp; To connect to the Root of the Public folder store you use the following enumeration.&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-c" start="1"&gt;&lt;li class="alt"&gt;$folderid=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot,&lt;span class="string"&gt;"user@mailbox.com"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$PublicfolderRoot&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Other bits and pieces for folders&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;To Set the Homepage of folder in EWS see &lt;a href="http://www.infinitec.de/post/2011/10/05/Setting-the-Homepage-of-an-Exchange-folder-using-the-EWS-Managed-API.aspx"&gt;http://www.infinitec.de/post/2011/10/05/Setting-the-Homepage-of-an-Exchange-folder-using-the-EWS-Managed-API.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;That's about it for this post if you have any specific question about folders in EWS with powershell post a comment and I'll try to update this post. In the next post in this series well look into Items.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-6283936843597359353?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/6283936843597359353/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=6283936843597359353' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6283936843597359353'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6283936843597359353'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2012/01/ews-managed-api-and-powershell-how-to_23.html' title='EWS Managed API and Powershell How-To series Part 2 - Folders'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-7iMazCsaGSQ/TxZlesIGUCI/AAAAAAAAADU/UlIuimdX7rw/s72-c/Capture88.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-7671407823987891491</id><published>2012-01-10T20:51:00.000+11:00</published><updated>2012-01-10T20:51:32.863+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>EWS Managed API and Powershell How-To series Part 1</title><content type='html'>I thought I'd start the year with a series of posts that goes back over the basics of using the EWS Managed API from Powershell and provides a modular remarked example that you can easily cut and paste to build your own scripts. Along the way in this series I'll show a whole bunch of examples around specific things.&lt;br /&gt;&lt;br /&gt;As a starting point for versions this will be Powershell Version 2.0&amp;nbsp; and the EWS Managed API 1.1 (which will soon change to 1.2 once released) &lt;a href="http://www.microsoft.com/download/en/details.aspx?id=13480"&gt;http://www.microsoft.com/download/en/details.aspx?id=13480.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The starting point for any EWS script your going to write is connecting to Exchange for which there are three important pieces of information you will need. Firstly you need to know the version of Exchange your running in this script its going to be held in the following variable&lt;br /&gt;&lt;br /&gt;$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1&lt;br /&gt;&lt;br /&gt;Other valid values for Exchange 2007 would be&lt;br /&gt;&lt;br /&gt;$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1&lt;br /&gt;&lt;br /&gt;The next thing you need to know is what security credentials your going to use to connect to the Mailbox you want to access. There are two options available for this you can specify the credentials in your code (or prompt for them using Get-Credential). Or the other option is to use the default logged on user credentials (or from a scheduled task etc).&lt;br /&gt;&lt;br /&gt;The last thing piece of information you need is the URL to the CAS (Client Access Server) you are going to send the EWS requests through which you can find using Autodiscover if this is setup or you can hard code the URL of a CAS server to use. One word of note with Auto-discover and the Managed API is by default it will first perform a SCP look-up of Active Directory to find the Autodiscover EndPoint and if that fails it will then perform a DNS lookup. If you want more control over this process have a look at another script I've posted &lt;a href="http://gsexdev.blogspot.com/2011/07/using-autodiscover-in-powershell-with.html"&gt;http://gsexdev.blogspot.com/2011/07/using-autodiscover-in-powershell-with.html&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The last optional section in the connectivity script is an option to use EWS Impersonation this allows you to access another users mailbox with the effective security credentials of the owner of that mailbox. EWS Impersonation is configured via RBAC on 2010 see &lt;a href="http://msdn.microsoft.com/en-us/library/bb204095%28v=exchg.140%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb204095%28v=exchg.140%29.aspx.&lt;/a&gt; For more information on impersonation see &lt;a href="http://blogs.msdn.com/b/exchangedev/archive/2009/06/15/exchange-impersonation-vs-delegate-access.aspx"&gt;http://blogs.msdn.com/b/exchangedev/archive/2009/06/15/exchange-impersonation-vs-delegate-access.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thats about it from a connectivity and security perspective in the next post I'll go over folders inside and out. I've posted a copy of the connectivity script &lt;a href="http://msgdev.mvps.org/exdevblog/ConnectToExchange.zip"&gt;here&lt;/a&gt; the script itself looks like.&lt;br /&gt;&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;##&amp;nbsp;EWS&amp;nbsp;Managed&amp;nbsp;API&amp;nbsp;Connect Script&lt;/span&gt; &lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;##&amp;nbsp;Requires&amp;nbsp;the&amp;nbsp;EWS&amp;nbsp;Managed&amp;nbsp;API&amp;nbsp;and&amp;nbsp;Powershell&amp;nbsp;V2.0&amp;nbsp;or&amp;nbsp;greator&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;##&amp;nbsp;Load&amp;nbsp;Managed&amp;nbsp;API&amp;nbsp;dll&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;Add-Type&amp;nbsp;-Path&amp;nbsp;&lt;span class="string"&gt;"C:\Program&amp;nbsp;Files\Microsoft\Exchange\Web&amp;nbsp;Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;##&amp;nbsp;Set&amp;nbsp;Exchange&amp;nbsp;Version&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$ExchangeVersion&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;##&amp;nbsp;Create&amp;nbsp;Exchange&amp;nbsp;Service&amp;nbsp;Object&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExchangeService(&lt;span class="variable"&gt;$ExchangeVersion&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;##&amp;nbsp;Set&amp;nbsp;Credentials&amp;nbsp;to&amp;nbsp;use&amp;nbsp;two&amp;nbsp;options&amp;nbsp;are&amp;nbsp;availible&amp;nbsp;Option1&amp;nbsp;to&amp;nbsp;use&amp;nbsp;explict&amp;nbsp;credentials&amp;nbsp;or&amp;nbsp;Option&amp;nbsp;2&amp;nbsp;use&amp;nbsp;the&amp;nbsp;Default&amp;nbsp;(logged&amp;nbsp;On)&amp;nbsp;credentials&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Credentials&amp;nbsp;Option&amp;nbsp;1&amp;nbsp;using&amp;nbsp;UPN&amp;nbsp;for&amp;nbsp;the&amp;nbsp;windows&amp;nbsp;Account&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$creds&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;System.Net.NetworkCredential(&lt;span class="string"&gt;"user@domain.com"&lt;/span&gt;,&lt;span class="string"&gt;"password"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.Credentials&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$creds&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#Credentials&amp;nbsp;Option&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#service.UseDefaultCredentials&amp;nbsp;=&amp;nbsp;$true&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;##&amp;nbsp;Choose&amp;nbsp;to&amp;nbsp;ignore&amp;nbsp;any&amp;nbsp;SSL&amp;nbsp;Warning&amp;nbsp;issues&amp;nbsp;caused&amp;nbsp;by&amp;nbsp;Self&amp;nbsp;Signed&amp;nbsp;Certificates&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;[System.Net.ServicePointManager]::ServerCertificateValidationCallback&amp;nbsp;=&amp;nbsp;{&lt;span class="variable"&gt;$true&lt;/span&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;##&amp;nbsp;Set&amp;nbsp;the&amp;nbsp;URL&amp;nbsp;of&amp;nbsp;the&amp;nbsp;CAS&amp;nbsp;(Client&amp;nbsp;Access&amp;nbsp;Server)&amp;nbsp;to&amp;nbsp;use&amp;nbsp;two&amp;nbsp;options&amp;nbsp;are&amp;nbsp;availbe&amp;nbsp;to&amp;nbsp;use&amp;nbsp;Autodiscover&amp;nbsp;to&amp;nbsp;find&amp;nbsp;the&amp;nbsp;CAS&amp;nbsp;URL&amp;nbsp;or&amp;nbsp;Hardcode&amp;nbsp;the&amp;nbsp;CAS&amp;nbsp;to&amp;nbsp;use&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#CAS&amp;nbsp;URL&amp;nbsp;Option&amp;nbsp;1&amp;nbsp;Autodiscover&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.AutodiscoverUrl(&lt;span class="string"&gt;"email@domain.com"&lt;/span&gt;,{&lt;span class="variable"&gt;$true&lt;/span&gt;})&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;"Using&amp;nbsp;CAS&amp;nbsp;Server&amp;nbsp;:&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$Service&lt;/span&gt;.url&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#CAS&amp;nbsp;URL&amp;nbsp;Option&amp;nbsp;2&amp;nbsp;Hardcoded&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;#$uri=[system.URI]&amp;nbsp;"https://casservername/ews/exchange.asmx"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#$service.Url&amp;nbsp;=&amp;nbsp;$uri&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;##&amp;nbsp;Optional&amp;nbsp;section&amp;nbsp;for&amp;nbsp;Exchange&amp;nbsp;Impersonation&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#$service.ImpersonatedUserId&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress,&amp;nbsp;"email@domain.com")&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&amp;nbsp;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-7671407823987891491?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/7671407823987891491/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=7671407823987891491' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7671407823987891491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7671407823987891491'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2012/01/ews-managed-api-and-powershell-how-to.html' title='EWS Managed API and Powershell How-To series Part 1'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-3206495655087054920</id><published>2011-12-08T21:51:00.001+11:00</published><updated>2011-12-08T22:31:35.807+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010 SP2'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS'/><title type='text'>Using the new EWS password expiration operation in Exchange 2010 SP2 in Powershell</title><content type='html'>If it hadn't escaped your notice Exchange 2010 SP2 was released this week although from an EWS perspective there isn't that much to shout about one of the interesting new operations is the &lt;a href="http://msdn.microsoft.com/en-us/library/hh505720%28v=EXCHG.140%29.aspx"&gt;GetPasswordExpiration&lt;/a&gt; operation. This allows you to get the DateTime when the password for an account will expire. Currently version 1.1 of the Managed API doesn't support this operation but from the information that has been released the next version should. In the meantime you can take advantage of this new operation using some raw SOAP. &lt;br /&gt;&lt;br /&gt;The following is a quick sample script that makes a GetPasswordExpiration request there is some SSL ignore code so it should run okay in a test environment without a valid SSL cert. To use this script you need to configure the following variables.&lt;br /&gt;&lt;br /&gt;$MailboxName = "user@domain.com"&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;$cred = New-Object System.Net.NetworkCredential("user@domamin.com","password")&lt;br /&gt;&lt;br /&gt;If you don't have autodiscover configured if your trying in a dev/test enviroment you can also hardcode the CASURL in&lt;br /&gt;&lt;br /&gt;$mbMailboxFolderURI = New-Object System.Uri("https://192.168.42.132/ews/exchange.asmx")&amp;nbsp; &lt;br /&gt;&lt;br /&gt;I've put a download of this script &lt;a href="http://msgdev.mvps.org/exdevblog/pwdexp.zip"&gt;here &lt;/a&gt;the script itself looks like&lt;br /&gt;&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"user@domain.com"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$cred&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;System.Net.NetworkCredential(&lt;span class="string"&gt;"user@domamin.com"&lt;/span&gt;,&lt;span class="string"&gt;"password"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$dllpath&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"C:\Program&amp;nbsp;Files\Microsoft\Exchange\Web&amp;nbsp;Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;[void][Reflection.Assembly]::LoadFile(&lt;span class="variable"&gt;$dllpath&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.TraceEnabled&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$false&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.Credentials&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$cred&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.autodiscoverurl(&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;,{&lt;span class="variable"&gt;$true&lt;/span&gt;})&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;##&amp;nbsp;Code&amp;nbsp;From&amp;nbsp;http://poshcode.org/624&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="comment"&gt;##&amp;nbsp;Create&amp;nbsp;a&amp;nbsp;compilation&amp;nbsp;environment&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Provider&lt;/span&gt;=&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.CSharp.CSharpCodeProvider&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$Compiler&lt;/span&gt;=&lt;span class="variable"&gt;$Provider&lt;/span&gt;.CreateCompiler()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Params&lt;/span&gt;=&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;System.CodeDom.Compiler.CompilerParameters&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$Params&lt;/span&gt;.GenerateExecutable=&lt;span class="variable"&gt;$False&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Params&lt;/span&gt;.GenerateInMemory=&lt;span class="variable"&gt;$True&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$Params&lt;/span&gt;.IncludeDebugInformation=&lt;span class="variable"&gt;$False&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Params&lt;/span&gt;.ReferencedAssemblies.Add(&lt;span class="string"&gt;"System.DLL"&lt;/span&gt;)&amp;nbsp;|&amp;nbsp;&lt;span class="builtin"&gt;Out-Null&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$TASource&lt;/span&gt;=@&lt;span class="string"&gt;'&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;namespace&amp;nbsp;Local.ToolkitExtensions.Net.CertificatePolicy{&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;class&amp;nbsp;TrustAll&amp;nbsp;:&amp;nbsp;System.Net.ICertificatePolicy&amp;nbsp;{&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;TrustAll()&amp;nbsp;{&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;CheckValidationResult(System.Net.ServicePoint&amp;nbsp;sp,&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Security.Cryptography.X509Certificates.X509Certificate&amp;nbsp;cert,&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.Net.WebRequest&amp;nbsp;req,&amp;nbsp;int&amp;nbsp;problem)&amp;nbsp;{&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;'&lt;/span&gt;@&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$TAResults&lt;/span&gt;=&lt;span class="variable"&gt;$Provider&lt;/span&gt;.CompileAssemblyFromSource(&lt;span class="variable"&gt;$Params&lt;/span&gt;,&lt;span class="variable"&gt;$TASource&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$TAAssembly&lt;/span&gt;=&lt;span class="variable"&gt;$TAResults&lt;/span&gt;.CompiledAssembly&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;##&amp;nbsp;We&amp;nbsp;now&amp;nbsp;create&amp;nbsp;an&amp;nbsp;instance&amp;nbsp;of&amp;nbsp;the&amp;nbsp;TrustAll&amp;nbsp;and&amp;nbsp;attach&amp;nbsp;it&amp;nbsp;to&amp;nbsp;the&amp;nbsp;ServicePointManager&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$TrustAll&lt;/span&gt;=&lt;span class="variable"&gt;$TAAssembly&lt;/span&gt;.CreateInstance(&lt;span class="string"&gt;"Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;[System.Net.ServicePointManager]::CertificatePolicy=&lt;span class="variable"&gt;$TrustAll&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;##&amp;nbsp;end&amp;nbsp;code&amp;nbsp;from&amp;nbsp;http://poshcode.org/624&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$expRequest&lt;/span&gt;&amp;nbsp;=&amp;nbsp;@&lt;span class="string"&gt;"&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;lt;?xml&amp;nbsp;version="&lt;/span&gt;1.0&lt;span class="string"&gt;"&amp;nbsp;encoding="&lt;/span&gt;utf-8&lt;span class="string"&gt;"?&amp;gt;&amp;lt;soap:Envelope&amp;nbsp;xmlns:soap="&lt;/span&gt;http://schemas.xmlsoap.org/soap/envelope/&lt;span class="string"&gt;"&amp;nbsp;xmlns:xsi="&lt;/span&gt;http://www.w3.org/2001/XMLSchema-instance&lt;span class="string"&gt;"&amp;nbsp;xmlns:xsd="&lt;/span&gt;http://www.w3.org/2001/XMLSchema&lt;span class="string"&gt;"&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;lt;soap:Header&amp;gt;&amp;lt;RequestServerVersion&amp;nbsp;Version="&lt;/span&gt;Exchange2010_SP2&lt;span class="string"&gt;"&amp;nbsp;xmlns="&lt;/span&gt;http://schemas.microsoft.com/exchange/services/2006/types&lt;span class="string"&gt;"&amp;nbsp;/&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;lt;/soap:Header&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;lt;soap:Body&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;lt;GetPasswordExpirationDate&amp;nbsp;xmlns="&lt;/span&gt;http://schemas.microsoft.com/exchange/services/2006/messages&lt;span class="string"&gt;"&amp;gt;&amp;lt;MailboxSmtpAddress&amp;gt;$MailboxName&amp;lt;/MailboxSmtpAddress&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;lt;/GetPasswordExpirationDate&amp;gt;&amp;lt;/soap:Body&amp;gt;&amp;lt;/soap:Envelope&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;"&lt;/span&gt;@&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$mbMailboxFolderURI&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;System.Uri(&lt;span class="variable"&gt;$service&lt;/span&gt;.url)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[System.Net.WebRequest]::Create(&lt;span class="variable"&gt;$mbMailboxFolderURI&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.KeepAlive&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$false&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Headers.Set(&lt;span class="string"&gt;"Pragma"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"no-cache"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Headers.Set(&lt;span class="string"&gt;"Translate"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"f"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Headers.Set(&lt;span class="string"&gt;"Depth"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"0"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.ContentType&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"text/xml"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.ContentLength&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$expRequest&lt;/span&gt;.Length;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Timeout&amp;nbsp;=&amp;nbsp;60000;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Method&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"POST"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Credentials&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$cred&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$bqByteQuery&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[System.Text.Encoding]::ASCII.GetBytes(&lt;span class="variable"&gt;$expRequest&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.ContentLength&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$bqByteQuery&lt;/span&gt;.Length;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$rsRequestStream&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.GetRequestStream();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$rsRequestStream&lt;/span&gt;.Write(&lt;span class="variable"&gt;$bqByteQuery&lt;/span&gt;,&amp;nbsp;0,&amp;nbsp;&lt;span class="variable"&gt;$bqByteQuery&lt;/span&gt;.Length);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$rsRequestStream&lt;/span&gt;.Close();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$wrWebResponse&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.GetResponse();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$rsResponseStream&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$wrWebResponse&lt;/span&gt;.GetResponseStream()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$sr&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;System.IO.StreamReader(&lt;span class="variable"&gt;$rsResponseStream&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$rdResponseDocument&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;System.Xml.XmlDocument&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$rdResponseDocument&lt;/span&gt;.LoadXml(&lt;span class="variable"&gt;$sr&lt;/span&gt;.ReadToEnd());&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$ExpNodes&lt;/span&gt;&amp;nbsp;=&amp;nbsp;@(&lt;span class="variable"&gt;$rdResponseDocument&lt;/span&gt;.getElementsByTagName(&lt;span class="string"&gt;"PasswordExpirationDate"&lt;/span&gt;))&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$ExpNodes&lt;/span&gt;[0].&lt;span class="string"&gt;'#text'&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-3206495655087054920?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/3206495655087054920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=3206495655087054920' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3206495655087054920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3206495655087054920'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/12/using-new-ews-password-expriation.html' title='Using the new EWS password expiration operation in Exchange 2010 SP2 in Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-8422280322673544663</id><published>2011-11-28T22:02:00.001+11:00</published><updated>2011-11-29T09:00:08.998+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OOF'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010 SP1'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='ExchangeOnline'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Creating an Out of Office Board using Remote Powershell, Mailtips and the EWS Managed API</title><content type='html'>Following on from my previous post on using &lt;a href="http://gsexdev.blogspot.com/2011/11/using-mailtips-in-ews-to-get-oof-out-of.html"&gt;MailTips &lt;/a&gt;and one of my other popular posts the &lt;a href="http://gsexdev.blogspot.com/2010/03/freebusy-board-for-exchange-ews-managed.html"&gt;FreeBusy board&lt;/a&gt; the following script creates an Out of office board that shows in one page peoples out of office status and if the out of office message is turned on it displays the OOF message for that user.Here's a quick picture of what it produces&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-YyHDkmAQHnE/TtNwgwDPK_I/AAAAAAAAADM/Hr50HvO8RCI/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="202" src="http://3.bp.blogspot.com/-YyHDkmAQHnE/TtNwgwDPK_I/AAAAAAAAADM/Hr50HvO8RCI/s400/Capture.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;So how does it work it takes advantage of MailTips within EWS to get the OOF status of a user and what the OOF message is if its set. If you have a large number of users it batches the MailTips request in batches of 100 to ensure the request is successful. To get the list of users to query it takes advantage of using Remote powershell and uses the Get-Mailbox cmdlet.&lt;br /&gt;&lt;br /&gt;The following script is setup to work with Office365 but will work OnPremise as well if change around the remote powershell URL.&lt;br /&gt;&lt;br /&gt;The following variables are those that need to be configured to run this script&lt;br /&gt;&lt;br /&gt;$UserName = "user@domain.com"&lt;br /&gt;$Password = "password"&lt;br /&gt;&lt;br /&gt;This is the username and password to use for both the remote powershell connection and it will also be used in the EWS Connection. &lt;br /&gt;&lt;br /&gt;$MailboxName = $UserName&lt;br /&gt;&lt;br /&gt;This line is setting the Sender email Address for MailTips to the above username if your using UPN's that are different from your SMTP addresses then you will need to change this variable.&lt;br /&gt;&lt;br /&gt;$rpRemotePowershell = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -credential $adminCredential&amp;nbsp; -Authentication Basic -AllowRedirection&lt;br /&gt;&lt;br /&gt;If your using this in a OnPrem environment then you need to change the URL and auth to suit your environment currently this is setup to connect to Office365.&lt;br /&gt;&lt;br /&gt;I've put a download of this script &lt;a href="http://msgdev.mvps.org/exdevblog/oofboard.zip"&gt;here &lt;/a&gt;the script itself looks like&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-c" start="1"&gt;&lt;li class="alt"&gt;$UserName&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"user@domain.com"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$Password&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"pasdfawrd."&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$mbHash&amp;nbsp;=&amp;nbsp;@{&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$MailboxName&amp;nbsp;=&amp;nbsp;$UserName&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$batchSize&amp;nbsp;=&amp;nbsp;100&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$global:oaBoard&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;""&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$Mailboxes&amp;nbsp;=&amp;nbsp;@()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$cred&amp;nbsp;=&amp;nbsp;New-Object&amp;nbsp;System.Net.NetworkCredential($UserName,$Password)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$secpassword&amp;nbsp;=&amp;nbsp;ConvertTo-SecureString&amp;nbsp;$Password&amp;nbsp;-AsPlainText&amp;nbsp;-Force&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$adminCredential&amp;nbsp;=&amp;nbsp;New-Object&amp;nbsp;-TypeName&amp;nbsp;System.Management.Automation.PSCredential&amp;nbsp;-argumentlist&amp;nbsp;$UserName,$secpassword&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;If(Get-PSSession&amp;nbsp;|&amp;nbsp;where-object&amp;nbsp;{$_.ConfigurationName&amp;nbsp;-eq&amp;nbsp;&lt;span class="string"&gt;"Microsoft.Exchange"&lt;/span&gt;}){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;write-host&amp;nbsp;&lt;span class="string"&gt;"Session&amp;nbsp;Exists"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="keyword"&gt;else&lt;/span&gt;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$rpRemotePowershell&amp;nbsp;=&amp;nbsp;New-PSSession&amp;nbsp;-ConfigurationName&amp;nbsp;Microsoft.Exchange&amp;nbsp;-ConnectionUri&amp;nbsp;https:&lt;span class="comment"&gt;//ps.outlook.com/powershell&amp;nbsp;-credential&amp;nbsp;$adminCredential&amp;nbsp;&amp;nbsp;-Authentication&amp;nbsp;Basic&amp;nbsp;-AllowRedirection&amp;nbsp;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$importresults&amp;nbsp;=&amp;nbsp;Import-PSSession&amp;nbsp;$rpRemotePowershell&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;get-mailbox&amp;nbsp;-ResultSize&amp;nbsp;unlimited&amp;nbsp;|&amp;nbsp;where-object&amp;nbsp;{$_.HiddenFromAddressListsEnabled&amp;nbsp;-eq&amp;nbsp;$&lt;span class="keyword"&gt;false&lt;/span&gt;}&amp;nbsp;&amp;nbsp;|&amp;nbsp;foreach-object{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;($mbHash.ContainsKey($_.WindowsEmailAddress.ToString())&amp;nbsp;-eq&amp;nbsp;$&lt;span class="keyword"&gt;false&lt;/span&gt;){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$mbHash.Add($_.WindowsEmailAddress.ToString(),$_.DisplayName)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$emailAddress&amp;nbsp;=&amp;nbsp;$_.WindowsEmailAddress.ToString()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$Mailboxes&amp;nbsp;+=&amp;nbsp;$emailAddress&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$dllpath&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"C:\Program&amp;nbsp;Files\Microsoft\Exchange\Web&amp;nbsp;Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;[&lt;span class="keyword"&gt;void&lt;/span&gt;][Reflection.Assembly]::LoadFile($dllpath)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$service&amp;nbsp;=&amp;nbsp;New-Object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$service.TraceEnabled&amp;nbsp;=&amp;nbsp;$&lt;span class="keyword"&gt;false&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$service.Credentials&amp;nbsp;=&amp;nbsp;$cred&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$service.autodiscoverurl($MailboxName,{$&lt;span class="keyword"&gt;true&lt;/span&gt;})&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="keyword"&gt;function&lt;/span&gt;&amp;nbsp;GetMailTips{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$mbMailboxFolderURI&amp;nbsp;=&amp;nbsp;New-Object&amp;nbsp;System.Uri($service.url)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$wrWebRequest&amp;nbsp;=&amp;nbsp;[System.Net.WebRequest]::Create($mbMailboxFolderURI)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$wrWebRequest.KeepAlive&amp;nbsp;=&amp;nbsp;$&lt;span class="keyword"&gt;false&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$wrWebRequest.Headers.Set(&lt;span class="string"&gt;"Pragma"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"no-cache"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$wrWebRequest.Headers.Set(&lt;span class="string"&gt;"Translate"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"f"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$wrWebRequest.Headers.Set(&lt;span class="string"&gt;"Depth"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"0"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$wrWebRequest.ContentType&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"text/xml"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$wrWebRequest.ContentLength&amp;nbsp;=&amp;nbsp;$expRequest.Length;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$wrWebRequest.Timeout&amp;nbsp;=&amp;nbsp;60000;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$wrWebRequest.Method&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"POST"&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$wrWebRequest.Credentials&amp;nbsp;=&amp;nbsp;$cred&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$bqByteQuery&amp;nbsp;=&amp;nbsp;[System.Text.Encoding]::ASCII.GetBytes($expRequest);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$wrWebRequest.ContentLength&amp;nbsp;=&amp;nbsp;$bqByteQuery.Length;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$rsRequestStream&amp;nbsp;=&amp;nbsp;$wrWebRequest.GetRequestStream();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$rsRequestStream.Write($bqByteQuery,&amp;nbsp;0,&amp;nbsp;$bqByteQuery.Length);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$rsRequestStream.Close();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$wrWebResponse&amp;nbsp;=&amp;nbsp;$wrWebRequest.GetResponse();&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$rsResponseStream&amp;nbsp;=&amp;nbsp;$wrWebResponse.GetResponseStream()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$sr&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;-object&amp;nbsp;System.IO.StreamReader($rsResponseStream);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$rdResponseDocument&amp;nbsp;=&amp;nbsp;New-Object&amp;nbsp;System.Xml.XmlDocument&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$rdResponseDocument.LoadXml($sr.ReadToEnd());&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$RecipientNodes&amp;nbsp;=&amp;nbsp;@($rdResponseDocument.getElementsByTagName(&lt;span class="string"&gt;"t:RecipientAddress"&lt;/span&gt;))&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$Datanodes&amp;nbsp;=&amp;nbsp;@($rdResponseDocument.getElementsByTagName(&lt;span class="string"&gt;"t:OutOfOffice"&lt;/span&gt;))&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="keyword"&gt;for&lt;/span&gt;($ic=0;$ic&amp;nbsp;-lt&amp;nbsp;$RecipientNodes.length;$ic++){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;($Datanodes[$ic].ReplyBody.Message&amp;nbsp;-eq&amp;nbsp;&lt;span class="string"&gt;""&lt;/span&gt;){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;tr&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;td&amp;gt;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;$mbHash[$RecipientNodes[$ic].EmailAddress]&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/td&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;td&amp;nbsp;bgcolor=`"&lt;/span&gt;#41A317`&lt;span class="string"&gt;"&amp;gt;In&amp;nbsp;the&amp;nbsp;Office&amp;lt;/td&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/tr&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;else&lt;/span&gt;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;tr&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;td&amp;gt;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;$mbHash[$RecipientNodes[$ic].EmailAddress]&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/td&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;td&amp;nbsp;bgcolor=`"&lt;/span&gt;#153E7E`&lt;span class="string"&gt;"&amp;gt;Out&amp;nbsp;of&amp;nbsp;the&amp;nbsp;Office&amp;lt;/td&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;td&amp;gt;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;$Datanodes[$ic].ReplyBody.Message&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/td&amp;gt;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/tr&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$expHeader&amp;nbsp;=&amp;nbsp;@&lt;span class="string"&gt;"&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;lt;?xml&amp;nbsp;version="&lt;/span&gt;1.0&lt;span class="string"&gt;"&amp;nbsp;encoding="&lt;/span&gt;utf-8&lt;span class="string"&gt;"?&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;&amp;lt;soap:Envelope&amp;nbsp;xmlns:soap="&lt;/span&gt;http:&lt;span class="comment"&gt;//schemas.xmlsoap.org/soap/envelope/"&amp;nbsp;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&amp;nbsp;xmlns:xsd="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;lt;soap:Header&amp;gt;&amp;lt;RequestServerVersion&amp;nbsp;Version="Exchange2010_SP1&lt;span class="string"&gt;"&amp;nbsp;xmlns="&lt;/span&gt;http:&lt;span class="comment"&gt;//schemas.microsoft.com/exchange/services/2006/types"&amp;nbsp;/&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;lt;/soap:Header&amp;gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;lt;soap:Body&amp;gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;lt;GetMailTips&amp;nbsp;xmlns="http:&lt;span class="comment"&gt;//schemas.microsoft.com/exchange/services/2006/messages"&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;lt;SendingAs&amp;gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;lt;EmailAddress&amp;nbsp;xmlns="http:&lt;span class="comment"&gt;//schemas.microsoft.com/exchange/services/2006/types"&amp;gt;$MailboxName&amp;lt;/EmailAddress&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;lt;/SendingAs&amp;gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;lt;Recipients&amp;gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;"@&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;table&amp;gt;&amp;lt;tr&amp;nbsp;bgcolor=`"&lt;/span&gt;#95aedc`&lt;span class="string"&gt;"&amp;gt;"&lt;/span&gt;&amp;nbsp;+&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;td&amp;nbsp;align=`"&lt;/span&gt;center`&lt;span class="string"&gt;"&amp;nbsp;style=`"&lt;/span&gt;width=200;`&lt;span class="string"&gt;"&amp;nbsp;&amp;gt;&amp;lt;b&amp;gt;User&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;"&lt;/span&gt;&amp;nbsp;+&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;td&amp;nbsp;align=`"&lt;/span&gt;center`&lt;span class="string"&gt;"&amp;nbsp;style=`"&lt;/span&gt;width=200;`&lt;span class="string"&gt;"&amp;nbsp;&amp;gt;&amp;lt;b&amp;gt;Status&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;"&lt;/span&gt;&amp;nbsp;+&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;td&amp;nbsp;align=`"&lt;/span&gt;center`&lt;span class="string"&gt;"&amp;nbsp;style=`"&lt;/span&gt;width=200;`&lt;span class="string"&gt;"&amp;nbsp;&amp;gt;&amp;lt;b&amp;gt;Message&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;"&lt;/span&gt;&amp;nbsp;+&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/tr&amp;gt;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"`r`n"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$expRequest&amp;nbsp;=&amp;nbsp;$expHeader&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$bCount&amp;nbsp;=0&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;foreach($mbMailbox&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;$Mailboxes){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$bCount++&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$expRequest&amp;nbsp;=&amp;nbsp;$expRequest&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;Mailbox&amp;nbsp;xmlns=`"&lt;/span&gt;http:&lt;span class="comment"&gt;//schemas.microsoft.com/exchange/services/2006/types`"&amp;gt;&amp;lt;EmailAddress&amp;gt;$mbMailbox&amp;lt;/EmailAddress&amp;gt;&amp;lt;/Mailbox&amp;gt;"&amp;nbsp;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;($bCount&amp;nbsp;-eq&amp;nbsp;$batchSize){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$expRequest&amp;nbsp;=&amp;nbsp;$expRequest&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/Recipients&amp;gt;&amp;lt;MailTipsRequested&amp;gt;OutOfOfficeMessage&amp;lt;/MailTipsRequested&amp;gt;&amp;lt;/GetMailTips&amp;gt;&amp;lt;/soap:Body&amp;gt;&amp;lt;/soap:Envelope&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GetMailTips&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$expRequest&amp;nbsp;=&amp;nbsp;$expHeader&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$bCount&amp;nbsp;=&amp;nbsp;0&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="keyword"&gt;if&lt;/span&gt;($bCount&amp;nbsp;-ne&amp;nbsp;0){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$expRequest&amp;nbsp;=&amp;nbsp;$expRequest&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/Recipients&amp;gt;&amp;lt;MailTipsRequested&amp;gt;OutOfOfficeMessage&amp;lt;/MailTipsRequested&amp;gt;&amp;lt;/GetMailTips&amp;gt;&amp;lt;/soap:Body&amp;gt;&amp;lt;/soap:Envelope&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GetMailTips&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;$global:oaBoard&amp;nbsp;=&amp;nbsp;$global:oaBoard&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/table&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;nbsp;&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;$global:oaBoard&amp;nbsp;|&amp;nbsp;out-file&amp;nbsp;&lt;span class="string"&gt;"c:\oofboard.htm"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-8422280322673544663?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/8422280322673544663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=8422280322673544663' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/8422280322673544663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/8422280322673544663'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/11/creating-out-of-office-board-using.html' title='Creating an Out of Office Board using Remote Powershell, Mailtips and the EWS Managed API'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-YyHDkmAQHnE/TtNwgwDPK_I/AAAAAAAAADM/Hr50HvO8RCI/s72-c/Capture.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-7051735637831593963</id><published>2011-11-08T17:08:00.002+11:00</published><updated>2011-11-08T17:08:25.749+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OOF'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010 SP1'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Using MailTips in EWS to get the OOF (Out of Office) Status of users with C# and Powershell</title><content type='html'>MailTips is one of the really useful new features of Exchange 2010 that can be exceedingly useful to anybody using Exchange Web Services. It provides access to Information such as the OOF status of a user or users within one WebService call and without the need for Full Access or elevated rights you would normally need with a GetUserOofSettings operations or using the Remote powershell cmdlets such as Get-MailboxAutoReplyConfiguration.&lt;br /&gt;&lt;br /&gt;The other thing MailTips are useful for apart from the other standard Mail-tips listed&lt;a href="http://msdn.microsoft.com/en-us/library/dd877060%28v=exchg.140%29.aspx"&gt; http://msdn.microsoft.com/en-us/library/dd877060%28v=exchg.140%29.aspx&lt;/a&gt; (things like the Max message size is useful for anybody sending email via EWS etc)&amp;nbsp; is the ability to create Custom MailTips. This gives you the ability to now retrieve a custom property that is stored within Active Directory via EWS. Which provides a workaround to not being able to access the information in the AD Custom Attributes &lt;a href="http://technet.microsoft.com/en-us/library/ee423541.aspx"&gt;http://technet.microsoft.com/en-us/library/ee423541.aspx&lt;/a&gt; currently in EWS.&lt;br /&gt;&lt;br /&gt;To use the EWS Mailtips operations you need to use WSDL Proxy objects or Custom SOAP code as currently these operations aren't available for use within the EWS Managed API. If you want to script it I would still combine it with EWS Managed API code because of ease of access to things like Autodiscover this gives you.&lt;br /&gt;&lt;br /&gt;I've created a powershell and C# sample of using the GetMailtips operation the C# looks like&lt;br /&gt;&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-c"&gt;&lt;li class="alt"&gt;ExchangeServiceBinding&amp;nbsp;esb&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;ExchangeServiceBinding(); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;esb.Credentials&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;NetworkCredential(&lt;span class="string"&gt;"user@domain.com"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"password"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;""&lt;/span&gt;); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;esb.Url&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"https://ch1prd0302.outlook.com/EWS/Exchange.asmx"&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;esb.RequestServerVersionValue&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;RequestServerVersion(); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;esb.RequestServerVersionValue.Version&amp;nbsp;=&amp;nbsp;ExchangeVersionType.Exchange2010_SP1; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;GetMessageTrackingReportRequestType&amp;nbsp;gmt&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;GetMessageTrackingReportRequestType(); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;GetMailTipsType&amp;nbsp;gmType&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;GetMailTipsType(); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;gmType.MailTipsRequested&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;MailTipTypes(); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;gmType.MailTipsRequested&amp;nbsp;=&amp;nbsp;MailTipTypes.OutOfOfficeMessage; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;gmType.Recipients&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;EmailAddressType[1]; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;EmailAddressType&amp;nbsp;rcip&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;EmailAddressType(); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;rcip.EmailAddress&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"user@domain.com"&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;gmType.Recipients[0]&amp;nbsp;=&amp;nbsp;rcip; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;EmailAddressType&amp;nbsp;sendAs&amp;nbsp;=&amp;nbsp;&lt;span class="keyword"&gt;new&lt;/span&gt;&amp;nbsp;EmailAddressType(); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;sendAs.EmailAddress&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"sender@domain.com"&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;gmType.SendingAs&amp;nbsp;=&amp;nbsp;sendAs; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;GetMailTipsResponseMessageType&amp;nbsp;gmResponse&amp;nbsp;=&amp;nbsp;esb.GetMailTips(gmType); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(gmResponse.ResponseClass&amp;nbsp;==&amp;nbsp;ResponseClassType.Success)&amp;nbsp;{ &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(gmResponse.ResponseMessages[0].MailTips.OutOfOffice.ReplyBody.Message&amp;nbsp;!=&amp;nbsp;&lt;span class="string"&gt;""&lt;/span&gt;) &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment"&gt;//User&amp;nbsp;Out &lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.WriteLine(gmResponse.ResponseMessages[0].MailTips.OutOfOffice.ReplyBody.Message); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;else&lt;/span&gt;&amp;nbsp;{&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="comment"&gt;//user&amp;nbsp;In &lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;With the Powershell example the following information needs to be configured&lt;br /&gt;&lt;br /&gt;$MailboxName = "sender@domain.com"&lt;br /&gt;&lt;br /&gt;Mailbox which will do the check from&lt;br /&gt;&amp;nbsp; &lt;br /&gt;$Mailboxes = @("user1@domain.com","user2@domain.com")&lt;br /&gt;&lt;br /&gt;Mailbox you want to check the OOF of (this is just an array or Strings) &amp;nbsp; &lt;br /&gt;&amp;nbsp; &lt;br /&gt;$cred = New-Object System.Net.NetworkCredential("user1@domain.com","password@#") &lt;br /&gt;&lt;br /&gt;Credentials to use&lt;br /&gt;&lt;br /&gt;I've put a download of the script &lt;a href="http://msgdev.mvps.org/exdevblog/getoof.zip"&gt;here&lt;/a&gt; the code itself looks like&lt;br /&gt;&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb"&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"sender@domain.com"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Mailboxes&lt;/span&gt;&amp;nbsp;=&amp;nbsp;@(&lt;span class="string"&gt;"user1@domain.com"&lt;/span&gt;,&lt;span class="string"&gt;"user2@domain.com"&lt;/span&gt;) &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$cred&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;System.Net.NetworkCredential(&lt;span class="string"&gt;"user1@domain.com"&lt;/span&gt;,&lt;span class="string"&gt;"password@#"&lt;/span&gt;) &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$dllpath&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"C:\Program&amp;nbsp;Files\Microsoft\Exchange\Web&amp;nbsp;Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;[void][Reflection.Assembly]::LoadFile(&lt;span class="variable"&gt;$dllpath&lt;/span&gt;) &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1) &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.TraceEnabled&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$false&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.Credentials&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$cred&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.autodiscoverurl(&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;,{&lt;span class="variable"&gt;$true&lt;/span&gt;}) &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$expRequest&lt;/span&gt;&amp;nbsp;=&amp;nbsp;@&lt;span class="string"&gt;" &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="string"&gt;&amp;lt;?xml&amp;nbsp;version="&lt;/span&gt;1.0&lt;span class="string"&gt;"&amp;nbsp;encoding="&lt;/span&gt;utf-8&lt;span class="string"&gt;"?&amp;gt; &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;lt;soap:Envelope&amp;nbsp;xmlns:soap="&lt;/span&gt;http://schemas.xmlsoap.org/soap/envelope/&lt;span class="string"&gt;"&amp;nbsp;xmlns:xsi="&lt;/span&gt;http://www.w3.org/2001/XMLSchema-instance&lt;span class="string"&gt;"&amp;nbsp;xmlns:xsd="&lt;/span&gt;http://www.w3.org/2001/XMLSchema&lt;span class="string"&gt;"&amp;gt; &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="string"&gt;&amp;lt;soap:Header&amp;gt;&amp;lt;RequestServerVersion&amp;nbsp;Version="&lt;/span&gt;Exchange2010_SP1&lt;span class="string"&gt;"&amp;nbsp;xmlns="&lt;/span&gt;http://schemas.microsoft.com/exchange/services/2006/types&lt;span class="string"&gt;"&amp;nbsp;/&amp;gt; &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;lt;/soap:Header&amp;gt; &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="string"&gt;&amp;lt;soap:Body&amp;gt; &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;lt;GetMailTips&amp;nbsp;xmlns="&lt;/span&gt;http://schemas.microsoft.com/exchange/services/2006/messages&lt;span class="string"&gt;"&amp;gt; &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="string"&gt;&amp;lt;SendingAs&amp;gt; &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;lt;EmailAddress&amp;nbsp;xmlns="&lt;/span&gt;http://schemas.microsoft.com/exchange/services/2006/types&lt;span class="string"&gt;"&amp;gt;$MailboxName&amp;lt;/EmailAddress&amp;gt; &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="string"&gt;&amp;lt;/SendingAs&amp;gt; &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;&amp;lt;Recipients&amp;gt; &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="string"&gt;"&lt;/span&gt;@ &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="keyword"&gt;foreach&lt;/span&gt;(&lt;span class="variable"&gt;$mbMailbox&lt;/span&gt;&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class="variable"&gt;$Mailboxes&lt;/span&gt;){ &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$expRequest&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$expRequest&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;Mailbox&amp;nbsp;xmlns=`"&lt;/span&gt;http://schemas.microsoft.com/exchange/services/2006/types`&lt;span class="string"&gt;"&amp;gt;&amp;lt;EmailAddress&amp;gt;$mbMailbox&amp;lt;/EmailAddress&amp;gt;&amp;lt;/Mailbox&amp;gt;"&lt;/span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;} &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$expRequest&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$expRequest&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;lt;/Recipients&amp;gt;&amp;lt;MailTipsRequested&amp;gt;OutOfOfficeMessage&amp;lt;/MailTipsRequested&amp;gt;&amp;lt;/GetMailTips&amp;gt;&amp;lt;/soap:Body&amp;gt;&amp;lt;/soap:Envelope&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$mbMailboxFolderURI&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;System.Uri(&lt;span class="variable"&gt;$service&lt;/span&gt;.url) &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[System.Net.WebRequest]::Create(&lt;span class="variable"&gt;$mbMailboxFolderURI&lt;/span&gt;) &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.KeepAlive&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$false&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Headers.Set(&lt;span class="string"&gt;"Pragma"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"no-cache"&lt;/span&gt;); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Headers.Set(&lt;span class="string"&gt;"Translate"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"f"&lt;/span&gt;); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Headers.Set(&lt;span class="string"&gt;"Depth"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"0"&lt;/span&gt;); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.ContentType&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"text/xml"&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.ContentLength&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$expRequest&lt;/span&gt;.Length; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Timeout&amp;nbsp;=&amp;nbsp;60000; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Method&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"POST"&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.Credentials&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$cred&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$bqByteQuery&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[System.Text.Encoding]::ASCII.GetBytes(&lt;span class="variable"&gt;$expRequest&lt;/span&gt;); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.ContentLength&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$bqByteQuery&lt;/span&gt;.Length; &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$rsRequestStream&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.GetRequestStream(); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$rsRequestStream&lt;/span&gt;.Write(&lt;span class="variable"&gt;$bqByteQuery&lt;/span&gt;,&amp;nbsp;0,&amp;nbsp;&lt;span class="variable"&gt;$bqByteQuery&lt;/span&gt;.Length); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$rsRequestStream&lt;/span&gt;.Close(); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$wrWebResponse&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$wrWebRequest&lt;/span&gt;.GetResponse(); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$rsResponseStream&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$wrWebResponse&lt;/span&gt;.GetResponseStream() &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$sr&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;System.IO.StreamReader(&lt;span class="variable"&gt;$rsResponseStream&lt;/span&gt;); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$rdResponseDocument&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;System.Xml.XmlDocument &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$rdResponseDocument&lt;/span&gt;.LoadXml(&lt;span class="variable"&gt;$sr&lt;/span&gt;.ReadToEnd()); &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="variable"&gt;$RecipientNodes&lt;/span&gt;&amp;nbsp;=&amp;nbsp;@(&lt;span class="variable"&gt;$rdResponseDocument&lt;/span&gt;.getElementsByTagName(&lt;span class="string"&gt;"t:RecipientAddress"&lt;/span&gt;)) &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Datanodes&lt;/span&gt;&amp;nbsp;=&amp;nbsp;@(&lt;span class="variable"&gt;$rdResponseDocument&lt;/span&gt;.getElementsByTagName(&lt;span class="string"&gt;"t:OutOfOffice"&lt;/span&gt;)) &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;span class="keyword"&gt;for&lt;/span&gt;(&lt;span class="variable"&gt;$ic&lt;/span&gt;=0;&lt;span class="variable"&gt;$ic&lt;/span&gt;&amp;nbsp;-lt&amp;nbsp;&lt;span class="variable"&gt;$RecipientNodes&lt;/span&gt;.length;&lt;span class="variable"&gt;$ic&lt;/span&gt;++){ &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;(&lt;span class="variable"&gt;$Datanodes&lt;/span&gt;[&lt;span class="variable"&gt;$ic&lt;/span&gt;].ReplyBody.Message&amp;nbsp;-eq&amp;nbsp;&lt;span class="string"&gt;""&lt;/span&gt;){ &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$RecipientNodes&lt;/span&gt;[&lt;span class="variable"&gt;$ic&lt;/span&gt;].EmailAddress&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;nbsp;:&amp;nbsp;In&amp;nbsp;the&amp;nbsp;Office"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;else&lt;/span&gt;{ &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$RecipientNodes&lt;/span&gt;[&lt;span class="variable"&gt;$ic&lt;/span&gt;].EmailAddress&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;nbsp;:&amp;nbsp;Out&amp;nbsp;of&amp;nbsp;Office"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;} &amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-7051735637831593963?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/7051735637831593963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=7051735637831593963' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7051735637831593963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7051735637831593963'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/11/using-mailtips-in-ews-to-get-oof-out-of.html' title='Using MailTips in EWS to get the OOF (Out of Office) Status of users with C# and Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-4082408996987197338</id><published>2011-10-22T11:26:00.000+11:00</published><updated>2011-10-24T21:47:29.120+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='permissions'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Changing Folder and Calendar Permissions in Exchange using the EWS Managed API and powershell</title><content type='html'>While Exchange 2010 provides some really good cmdlets now for setting and changing folder permissions such as Set-MailboxFolderPermission &lt;a href="http://technet.microsoft.com/en-us/library/ff522363.aspx"&gt;http://technet.microsoft.com/en-us/library/ff522363.aspx &lt;/a&gt;. Using EWS to do this can still be useful in circumstances where the cmdlets can't be used or your having problems with localized folder names or you want to take advantage of EWS Impersonation to get around any issues your having with acquiring the correct rights to make the changes you might need.&lt;br /&gt;&lt;br /&gt;I'll look at the example of changing the default calendar permissions of the default ACL on the calendar as this is one of the harder things to do and there are a few points that can catch you out.&lt;br /&gt;&lt;br /&gt;First point is that when you modify permissions with EWS you basically grab the DACL from the server make your changes locally to the DACL and the post it back in a Update Folder operation. This means the logic you use on the client side needs to be up to dealing with this. The permissions object in the Managed API has a Add and Remove methods and you have the ability to modify am ACE within the permissions collection. The one problem you can have is if the Folder permissions is currently set to custom and you try to use one the default FolderPermissionLevel. You will also have problem if you don't check the current collection and try to add a duplicate ACE into the collection.&lt;br /&gt;&lt;br /&gt;A simple way to solve this is to first search the current collection for any existing ACE entries and remove the existing ACE then add the new rights you want set using the Add method. The other issue you need to deal with when setting the calendar folder permission is to also make sure you set the corresponding rights on the FreeBusy Data folder or you may have problems such as explained in &lt;a href="http://support.microsoft.com/kb/184151%20"&gt;http://support.microsoft.com/kb/184151 &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I've put together two examples both of these use EWS Impersonation which you can configure in 2010 &lt;span id="yui_3_2_0_1_1319241587931205"&gt; via RBAC &lt;a href="http://msdn.microsoft.com/en-us/library/bb204095%28v=EXCHG.140%29.aspx" target="_blank"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;http://msdn.microsoft.com/en-us/library/bb204095%28v=EXCHG.140%29.aspx&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;There are 3 varibles in the script you need to modify&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;$MailboxName = "user@domain.com"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;This is the mailbox you want to make the changes and what will be impersonated&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;&lt;br /&gt;$Permission = [Microsoft.Exchange.WebServices.Data.FolderPermissionLevel]::Editor&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;&lt;br /&gt;This is the rights you want to set&lt;br /&gt;&lt;br /&gt;$credentials = New-Object System.Net.NetworkCredential("user@domain.com,"password")&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;These are the user credentials to use this user must have impersonation rights&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I've posted both examples up &lt;a href="http://msgdev.mvps.org/exdevblog/ewsfpDef.zip"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;In the first example this shows how to set the Default permissions for the default user on the Calendar to Editor&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id="yui_3_2_0_1_1319241587931205"&gt;&lt;span class="yshortcuts" id="lw_1319241701_0"&gt;The second Example shows how to set calendar permission for a particular user to Editor this example looks like&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"mailbox@domain.com"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&amp;nbsp;&lt;/ol&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$credentials&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;System.Net.NetworkCredential(&lt;span class="string"&gt;"user@domain.com"&lt;/span&gt;,&lt;span class="string"&gt;"Password#"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$NewACLUser&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"newacl@domain.com"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$dllpath&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"C:\Program&amp;nbsp;Files\Microsoft\Exchange\Web&amp;nbsp;Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;[void][Reflection.Assembly]::LoadFile(&lt;span class="variable"&gt;$dllpath&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$Permission&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.FolderPermissionLevel]::Editor&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt; &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.Credentials&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$credentials&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.AutodiscoverUrl(&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;,{&lt;span class="variable"&gt;$true&lt;/span&gt;})&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.ImpersonatedUserId&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress,&amp;nbsp;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="keyword"&gt;function&lt;/span&gt;&amp;nbsp;addFolderPerm(&lt;span class="variable"&gt;$folder&lt;/span&gt;){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$existingperm&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;foreach&lt;/span&gt;(&lt;span class="variable"&gt;$fperm&lt;/span&gt;&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class="variable"&gt;$folder&lt;/span&gt;.Permissions){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;(&lt;span class="variable"&gt;$fperm&lt;/span&gt;.UserId.StandardUser&amp;nbsp;-eq&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span class="variable"&gt;$fperm&lt;/span&gt;.UserId.PrimarySmtpAddress.ToLower()&amp;nbsp;-eq&amp;nbsp;&lt;span class="variable"&gt;$NewACLUser&lt;/span&gt;.ToLower()){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$existingperm&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$fperm&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;(&lt;span class="variable"&gt;$existingperm&lt;/span&gt;&amp;nbsp;-ne&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$folder&lt;/span&gt;.Permissions.Remove(&lt;span class="variable"&gt;$existingperm&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$newfp&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderPermission(&lt;span class="variable"&gt;$NewACLUser&lt;/span&gt;,&lt;span class="variable"&gt;$Permission&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$folder&lt;/span&gt;.Permissions.Add(&lt;span class="variable"&gt;$newfp&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$folder&lt;/span&gt;.Update()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;"Checking&amp;nbsp;:&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$folderidcnt&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Calendar&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.Folder]::Bind(&lt;span class="variable"&gt;$service&lt;/span&gt;,&lt;span class="variable"&gt;$folderidcnt&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="string"&gt;"Set&amp;nbsp;Calendar&amp;nbsp;Rights"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;addFolderPerm(&lt;span class="variable"&gt;$Calendar&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$sf1&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,&lt;span class="string"&gt;"Freebusy&amp;nbsp;Data"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderView(1000)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;.Traversal&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.FolderTraversal]::Shallow;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$folderidRoot&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$Service&lt;/span&gt;.FindFolders(&lt;span class="variable"&gt;$folderidRoot&lt;/span&gt;,&lt;span class="variable"&gt;$sf1&lt;/span&gt;,&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="keyword"&gt;if&lt;/span&gt;(&lt;span class="variable"&gt;$fiResult&lt;/span&gt;.Folders.Count&amp;nbsp;-eq&amp;nbsp;1){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"Set&amp;nbsp;FreeBusy&amp;nbsp;Rights"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Freebusyfld&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;.Folders[0]&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Freebusyfld&lt;/span&gt;.Load()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;addFolderPerm(&lt;span class="variable"&gt;$Freebusyfld&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-4082408996987197338?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/4082408996987197338/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=4082408996987197338' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/4082408996987197338'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/4082408996987197338'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/10/changing-folder-and-calendar.html' title='Changing Folder and Calendar Permissions in Exchange using the EWS Managed API and powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-529924799996096376</id><published>2011-09-30T17:34:00.000+10:00</published><updated>2011-09-30T17:42:39.298+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010 SP1'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Using EWS Streaming notifications in Powershell to trigger a script when new mail arrives in Exchange 2010 SP1</title><content type='html'>EWS Streaming notifications where a great addition to Exchange 2010 SP1 that went some way to filling that large emotional gap that all Exchange developers felt with the demise of Store Event sinks in Exchange 2010. There is some good information and samples of using Streaming notifications in .NET which are a good read at &lt;a href="http://msdn.microsoft.com/en-us/library/hh312849%28v=exchg.140%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/hh312849%28v=exchg.140%29.aspx&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/exchangedev/archive/2010/12/22/working-with-streaming-notifications-by-using-the-ews-managed-api.aspx"&gt;http://blogs.msdn.com/b/exchangedev/archive/2010/12/22/working-with-streaming-notifications-by-using-the-ews-managed-api.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Notifications in EWS are the method you can use to get real-time notifications of email arriving or a calendar appointments being created. To distill what happens with streaming notification in a few lines is that when you create a subscription request for a particular Exchange mailbox folder with a CAS server that connection remains open for a maximum time of 30 minutes (this bit is important). During the next 30 minutes if something happens in the folder your subscribed to the server can use the connection your app has opened to notify you that something has happened. If you understand how ActiveSync works the process is very similar using a hanging http request.&amp;nbsp; After 30 minutes you then need to re-establish the connection which re-establishes the notifications channel to your application. (this 30 minute period can be changed but 30 is the MAX)&lt;br /&gt;&lt;br /&gt;To use this within Powershell requires using some of the event features added in version 2.0 in particular the Register-ObjectEvent cmdlet. The cmldet allows you to subscribe to the events that are generated by a Microsoft .NET Framework object the object in question in this context is the StreamingSubscriptionConnection. This object has a few events the main one that fires when a NewMail arrives or an Item is created is the "OnNotificationEvent". The other import event is the "OnDisconnect" event which will fire when the subscription period ends or something else happens on the CAS side. The third event is the OnSubscriptionError which you need to work with for error checking and reliability.&lt;br /&gt;&lt;br /&gt;The following script uses Register-ObjectEvent to create a subscription that will start a process that will log the Subject of the Message that caused the notification to fire. What you receive from the server when a notification is fired is the ItemId of the object that fired it. To get more information about what caused the notification you need to bind to this Item Id. To achieve this the ExchangeService object is passed in via the MessageData and a normal EWS bind is done.&lt;br /&gt;&lt;br /&gt;The OnDisconnect Event is also registered so when this event fires the StreamingSubscriptionConnection open method is called which re-establishes the registration for another 30 minutes.&lt;br /&gt;&lt;br /&gt;Reliability as this is pretty simple example it just listens to one folder in a mailbox (you can change the subscription type to listen to all folder in a mailbox) and only works withing a currently opened powershell session. To create a reliable process that could be relied on in a business context requires that you put some form of maintenance routine around the Notification subscription which in fully blown .NET is a lot easier to handle so using powershell and notifications outside of prototyping isn't something I'd recommend. The other things to consider when using EWS notification is the default throttling limits in 2010 SP1. For EWS Subscriptions the maximum number subscription you can have by default is 20 Subs per account so if your looking a subscribing to say a large number of calendar folders your going to have problems with throttling once you go past 20 users (remembering throttling is enabled by default) this is particular acute if your trying to use ExchangeOnline where you can't change since (ouch).&lt;br /&gt;&lt;br /&gt;I've put a download of this script &lt;a href="http://msgdev.mvps.org/exdevblog/stmnot2.zip"&gt;here &lt;/a&gt;the code itself looks like&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"user@domain.com"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$dllpath&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"C:\Program&amp;nbsp;Files\Microsoft\Exchange\Web&amp;nbsp;Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;[void][Reflection.Assembly]::LoadFile(&lt;span class="variable"&gt;$dllpath&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.TraceEnabled&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$false&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.Credentials&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;System.Net.NetworkCredential(&lt;span class="string"&gt;"user@domain.com"&lt;/span&gt;,&lt;span class="string"&gt;"password"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.AutodiscoverUrl(&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;,{&lt;span class="variable"&gt;$true&lt;/span&gt;})&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fldArray&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId[]&amp;nbsp;1&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Inboxid&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fldArray&lt;/span&gt;[0]&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$Inboxid&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$stmsubscription&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$service&lt;/span&gt;.SubscribeToStreamingNotifications(&lt;span class="variable"&gt;$fldArray&lt;/span&gt;,&amp;nbsp;[Microsoft.Exchange.WebServices.Data.EventType]::NewMail)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$stmConnection&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection(&lt;span class="variable"&gt;$service&lt;/span&gt;,&amp;nbsp;30);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$stmConnection&lt;/span&gt;.AddSubscription(&lt;span class="variable"&gt;$stmsubscription&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;Register-ObjectEvent&amp;nbsp;-inputObject&amp;nbsp;&lt;span class="variable"&gt;$stmConnection&lt;/span&gt;&amp;nbsp;-eventName&amp;nbsp;&lt;span class="string"&gt;"OnNotificationEvent"&lt;/span&gt;&amp;nbsp;-Action&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;foreach&lt;/span&gt;(&lt;span class="variable"&gt;$notEvent&lt;/span&gt;&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class="variable"&gt;$event&lt;/span&gt;.SourceEventArgs.Events){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[String]&lt;span class="variable"&gt;$itmId&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$notEvent&lt;/span&gt;.ItemId.UniqueId.ToString()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$message&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind(&lt;span class="variable"&gt;$event&lt;/span&gt;.MessageData,&lt;span class="variable"&gt;$itmId&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"Subject&amp;nbsp;:&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$message&lt;/span&gt;.Subject&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;(&lt;span class="builtin"&gt;Get-Date&lt;/span&gt;)&amp;nbsp;|&amp;nbsp;&lt;span class="builtin"&gt;Out-File&lt;/span&gt;&amp;nbsp;c:\log2.txt&amp;nbsp;-Append&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;}&amp;nbsp;-MessageData&amp;nbsp;&lt;span class="variable"&gt;$service&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;Register-ObjectEvent&amp;nbsp;-inputObject&amp;nbsp;&lt;span class="variable"&gt;$stmConnection&lt;/span&gt;&amp;nbsp;-eventName&amp;nbsp;&lt;span class="string"&gt;"OnDisconnect"&lt;/span&gt;&amp;nbsp;-Action&amp;nbsp;{&lt;span class="variable"&gt;$event&lt;/span&gt;.MessageData.Open()}&amp;nbsp;-MessageData&amp;nbsp;&lt;span class="variable"&gt;$stmConnection&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$stmConnection&lt;/span&gt;.Open()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-529924799996096376?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/529924799996096376/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=529924799996096376' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/529924799996096376'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/529924799996096376'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/09/using-ews-streaming-notifications-in.html' title='Using EWS Streaming notifications in Powershell to trigger a script when new mail arrives in Exchange 2010 SP1'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-2096672434881761854</id><published>2011-09-16T21:16:00.000+10:00</published><updated>2011-09-16T21:16:12.592+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2003'/><category scheme='http://www.blogger.com/atom/ns#' term='WebDAV'/><category scheme='http://www.blogger.com/atom/ns#' term='RDO'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='ADSI'/><title type='text'>Getting Size and Item details for single folders in Exchange 2003 via Powershell</title><content type='html'>While this is now something you can do in one line in Exchange 2007 and 2010 if your migrating or managing 2000/3 you may want to get the Size and Item Count details of one particular mailbox folder for all users on a server eg how big the Inbox,SentItems or Calendar folder is. In Exchange 2003 you could get the Mailbox Size via WMI but to get an individual folder size you need to access the Mailbox itself (eg you can use pfdavadmin etc). To do this via Power shell for all users on the server you first need an ADSI query to get all the mailboxes on a particular server then you can use with WebDAV via the virtual admin root or MAPI via RDO\Redemption&amp;nbsp; http://www.dimastr.com/redemption/ which works well in Powershell. I have two scripts that use show how do to this using each of these API's which I've posted a downloadable copy &lt;a href="http://msgdev.mvps.org/exdevblog/atpinfo.zip"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To run these scripts you need to use the Netbios name of the server as a commandline parameter the RDO version of the script looks like&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$snServerName = $args[0]&lt;br /&gt;&lt;br /&gt;$Global:rptCollection = @()&lt;br /&gt;&lt;br /&gt;function QueryMailbox($mb){&lt;br /&gt;$mb&lt;br /&gt;$rdoSession = new-object -com Redemption.RDOSession&lt;br /&gt;$rdoSession.LogonExchangeMailbox($SmtpAddress,$snServerName)&lt;br /&gt;$calendar = $rdoSession.Stores.DefaultStore.GetDefaultFolder(9)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$Itmcnt = "" | select DisplayName,SMTPAddress,ItemCount,Size&lt;br /&gt;$Itmcnt.DisplayName = $displayName&lt;br /&gt;$Itmcnt.SMTPAddress = $SmtpAddress&lt;br /&gt;$Itmcnt.ItemCount = $calendar.Items.Count&lt;br /&gt;$Itmcnt.Size = [System.Math]::Round(($calendar.Fields(235405315) /1024),2)&lt;br /&gt;$Global:rptCollection += $Itmcnt&lt;br /&gt;$Itmcnt&lt;br /&gt;$rdoSession.logoff()&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function GetUsers(){&lt;br /&gt;$root = [ADSI]'LDAP://RootDSE' &lt;br /&gt;$cfConfigRootpath = "LDAP://" + $root.ConfigurationNamingContext.tostring()&lt;br /&gt;$dfDefaultRootPath = "LDAP://" + $root.DefaultNamingContext.tostring()&lt;br /&gt;$configRoot = [ADSI]$cfConfigRootpath &lt;br /&gt;$dfRoot = [ADSI]$dfDefaultRootPath&lt;br /&gt;$searcher = new-object System.DirectoryServices.DirectorySearcher($configRoot)&lt;br /&gt;$searcher.Filter = '(&amp;amp;(objectCategory=msExchExchangeServer)(cn=' + $snServerName&amp;nbsp; + '))'&lt;br /&gt;$searcher.PropertiesToLoad.Add("cn")&lt;br /&gt;$searcher.PropertiesToLoad.Add("gatewayProxy")&lt;br /&gt;$searcher.PropertiesToLoad.Add("legacyExchangeDN")&lt;br /&gt;$searcher1 = $searcher.FindAll()&lt;br /&gt;foreach ($server in $searcher1){ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $snServerEntry = New-Object System.DirectoryServices.directoryentry &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $snServerEntry = $server.GetDirectoryEntry() &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $snServerName = $snServerEntry.cn&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $snExchangeDN = $snServerEntry.legacyExchangeDN&lt;br /&gt;}&lt;br /&gt;$searcher.Filter = '(&amp;amp;(objectCategory=msExchRecipientPolicy)(cn=Default Policy))'&lt;br /&gt;$searcher1 = $searcher.FindAll()&lt;br /&gt;foreach ($recppolicies in $searcher1){ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; $gwaddrrs = New-Object System.DirectoryServices.directoryentry &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $gwaddrrs = $recppolicies.GetDirectoryEntry() &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach ($address in $gwaddrrs.gatewayProxy){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if($address.Substring(0,5) -ceq "SMTP:"){$dfAddress = $address.Replace("SMTP:@","")}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;}&lt;br /&gt;$arMbRoot = "https://" + $snServerName + "/exadmin/admin/" + $dfAddress + "/mbx/"&lt;br /&gt;$gfGALQueryFilter =&amp;nbsp; "(&amp;amp;(&amp;amp;(&amp;amp;(&amp;amp; (mailnickname=*)(!msExchHideFromAddressLists=TRUE)(| (&amp;amp;(objectCategory=person)" `&lt;br /&gt;+ "(objectClass=user)(msExchHomeServerName=" + $snExchangeDN + ")) )))))"&lt;br /&gt;$dfsearcher = new-object System.DirectoryServices.DirectorySearcher($dfRoot)&lt;br /&gt;$dfsearcher.Filter = $gfGALQueryFilter&lt;br /&gt;$searcher2 = $dfsearcher.FindAll()&lt;br /&gt;foreach ($uaUsers in $searcher2){ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; $uaUserAccount = New-Object System.DirectoryServices.directoryentry &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $uaUserAccount = $uaUsers.GetDirectoryEntry() &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach ($address in $uaUserAccount.proxyaddresses){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if($address.Substring(0,5) -ceq "SMTP:"){$uaAddress = $address.Replace("SMTP:","")}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $SmtpAddress = $uaAddress&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $displayName = $uaUserAccount.DisplayName[0]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; QueryMailbox($uaAddress)&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;GetUsers&lt;br /&gt;$Global:rptCollection | Export-Csv -NoTypeInformation c:\mailbox.csv&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-2096672434881761854?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/2096672434881761854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=2096672434881761854' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/2096672434881761854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/2096672434881761854'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/09/getting-size-and-item-details-for.html' title='Getting Size and Item details for single folders in Exchange 2003 via Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-4410061043966395943</id><published>2011-09-07T22:21:00.000+10:00</published><updated>2011-09-07T22:23:39.677+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010 SP1'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Create Search Folders using the EWS Managed API in a Mailbox or Archive Store using Powershell</title><content type='html'>Search folders are one of the suite of Exchange search options you can use programatically or to provide users with different views of their mailbox data in Outlook or OWA. Essentially a search folder is like a regular mailbox folder, except that it contains only links to messages in other folders that meet the criteria set in the search filter restriction which means that search folders are great for nonchanging, nondynamic queries. Search folders like Search Filters make use of restrictions in Exchange rather then using the Content Index which means that this comes along with some compromises ,if you are going to use search folders (or a lot of search filters) defiantly have a read of&amp;nbsp; &lt;a href="http://technet.microsoft.com/en-us/library/cc535025%28EXCHG.80%29.aspx"&gt;http://technet.microsoft.com/en-us/library/cc535025%28EXCHG.80%29.aspx&lt;/a&gt; .&lt;br /&gt;&lt;br /&gt;To create Search Folders using the EWS Managed API its pretty simple for search folders to be visible in Outlook you need to use the SearchFolders WellKnownFolderName enumeration which in a Mailbox relates to the Finder folder in the Non_IPM_Subtree.&lt;br /&gt;&lt;br /&gt;Eg the following will create a Search folder to find Items greater than 5 MB in a Mailbox &lt;br /&gt;&lt;br /&gt;$MailboxName = "user@domain.com"&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)&lt;br /&gt;$service.TraceEnabled = $false&lt;br /&gt;&lt;br /&gt;$service.Credentials = New-Object System.Net.NetworkCredential("user@domain.com","password")&lt;br /&gt;$service.AutodiscoverUrl($MailboxName ,{$true})&lt;br /&gt;&lt;br /&gt;$svFldid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::SearchFolders,$MailboxName)&lt;br /&gt;$SearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsGreaterThan([Microsoft.Exchange.WebServices.Data.ItemSchema]::Size, (5*1024*1024));&lt;br /&gt;$SearchFolder = new-object Microsoft.Exchange.WebServices.Data.SearchFolder($service);&lt;br /&gt;$searchFolder.SearchParameters.RootFolderIds.Add([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot);&lt;br /&gt;$searchFolder.SearchParameters.Traversal = [Microsoft.Exchange.WebServices.Data.SearchFolderTraversal]::Deep;&lt;br /&gt;$searchFolder.SearchParameters.SearchFilter = $SearchFilter&lt;br /&gt;$searchFolder.DisplayName = "Bigger then 5 MB";&lt;br /&gt;$searchFolder.Save($svFldid);&lt;br /&gt;&lt;br /&gt;If you want to create a Search folder in the Archive Store there's no enumeration for the SearchFolders root folder in the Archive Store so you first need to find the Finder folder in the Archive Store then you can use this when you create the Search Folder for example the following will create a Search folder to find Items greater than 5 MB in the Archive Store.&lt;br /&gt;&lt;br /&gt;$MailboxName = "user@domain.com"&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)&lt;br /&gt;$service.TraceEnabled = $false&lt;br /&gt;&lt;br /&gt;$service.Credentials = New-Object System.Net.NetworkCredential("user@domain.com","password")&lt;br /&gt;$service.AutodiscoverUrl($MailboxName ,{$true})&lt;br /&gt;&lt;br /&gt;$FolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(1);&lt;br /&gt;$fsf = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName, "Finder");&lt;br /&gt;$ffResult = $service.FindFolders([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::ArchiveRoot,$fsf, $FolderView)&lt;br /&gt;&lt;br /&gt;$SearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsGreaterThan([Microsoft.Exchange.WebServices.Data.ItemSchema]::Size, (5*1024*1024));&lt;br /&gt;$SearchFolder = new-object Microsoft.Exchange.WebServices.Data.SearchFolder($service);&lt;br /&gt;$searchFolder.SearchParameters.RootFolderIds.Add([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::ArchiveMsgFolderRoot);&lt;br /&gt;$searchFolder.SearchParameters.Traversal = [Microsoft.Exchange.WebServices.Data.SearchFolderTraversal]::Deep;&lt;br /&gt;$searchFolder.SearchParameters.SearchFilter = $SearchFilter&lt;br /&gt;$searchFolder.DisplayName = "Bigger then 5 MB";&lt;br /&gt;$searchFolder.Save($ffResult.folders[0].Id);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-4410061043966395943?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/4410061043966395943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=4410061043966395943' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/4410061043966395943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/4410061043966395943'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/09/create-search-folder-using-ews-managed.html' title='Create Search Folders using the EWS Managed API in a Mailbox or Archive Store using Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-8361757739153245429</id><published>2011-08-31T13:26:00.004+10:00</published><updated>2011-08-31T13:32:50.989+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='permissions'/><category scheme='http://www.blogger.com/atom/ns#' term='Audit'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='ADSI'/><category scheme='http://www.blogger.com/atom/ns#' term='Active Directory'/><title type='text'>Reading Extended Rights on an Exchange database using ADSI and C#</title><content type='html'>Although there are a few better methods of doing this these days this is still handy to have especially if your running older versions of Exchange or you want to audit the raw ACE's that are being added by RBAC in Exchange 2010. Extended rights get used for a number of things EWS Impersonation is one,  SendAs is another anyway here's an old C# sample I tripped over today.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.Security.AccessControl;&lt;br /&gt;using System.DirectoryServices;&lt;br /&gt;&lt;br /&gt;namespace showImpRights&lt;br /&gt;{&lt;br /&gt;    class Program&lt;br /&gt;    {&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            DirectoryEntry rootdse = new DirectoryEntry("LDAP://RootDSE");&lt;br /&gt;            DirectoryEntry cfg = new DirectoryEntry("LDAP://" +  rootdse.Properties["configurationnamingcontext"].Value);&lt;br /&gt;             DirectoryEntry exRights = new  DirectoryEntry("LDAP://cn=Extended-rights," +  rootdse.Properties["configurationnamingcontext"].Value);&lt;br /&gt;            Hashtable exRighthash = new Hashtable();&lt;br /&gt;            foreach (DirectoryEntry chent in exRights.Children) {&lt;br /&gt;                if( exRighthash.ContainsKey(chent.Properties["rightsGuid"].Value) == false){&lt;br /&gt;                exRighthash.Add(chent.Properties["rightsGuid"].Value,chent.Properties["DisplayName"].Value);}&lt;br /&gt;             }&lt;br /&gt;           &lt;br /&gt;            DirectorySearcher cfgsearch = new DirectorySearcher(cfg);&lt;br /&gt;            cfgsearch.Filter = "(objectCategory=msExchPrivateMDB)";&lt;br /&gt;            cfgsearch.PropertiesToLoad.Add("distinguishedName");&lt;br /&gt;            cfgsearch.SearchScope = SearchScope.Subtree;&lt;br /&gt;            SearchResultCollection res = cfgsearch.FindAll();&lt;br /&gt;            foreach (SearchResult se in res)&lt;br /&gt;            {&lt;br /&gt;                 DirectoryEntry ssStoreObj = se.GetDirectoryEntry();&lt;br /&gt;                ActiveDirectorySecurity StoreobjSec = ssStoreObj.ObjectSecurity;&lt;br /&gt;                 AuthorizationRuleCollection Storeacls =  StoreobjSec.GetAccessRules(true, true,  typeof(System.Security.Principal.SecurityIdentifier));&lt;br /&gt;                foreach (ActiveDirectoryAccessRule ace in Storeacls)&lt;br /&gt;                {&lt;br /&gt;                     if (ace.IdentityReference.Value != "S-1-5-7" &amp;amp;  ace.IdentityReference.Value != "S-1-1-0" &amp;amp; ace.IsInherited !=  true)&lt;br /&gt;                    {&lt;br /&gt;                        DirectoryEntry sidUser = new DirectoryEntry("LDAP://&lt;sid=" value=""&gt;");&lt;br /&gt;                        Console.WriteLine(sidUser.Properties["DisplayName"].Value.ToString());&lt;br /&gt;                        Console.WriteLine(exRighthash[ace.ObjectType.ToString()].ToString());&lt;br /&gt;                     }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;           &lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/sid="&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-8361757739153245429?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/8361757739153245429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=8361757739153245429' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/8361757739153245429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/8361757739153245429'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/08/reading-extended-rights-on-exchange.html' title='Reading Extended Rights on an Exchange database using ADSI and C#'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-7868428038425123531</id><published>2011-08-05T21:31:00.007+10:00</published><updated>2011-08-06T08:11:15.582+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Using the AllItems Search folder from Outlook 2010 on Exchange 2010 with Powershell and the EWS Managed API</title><content type='html'>Search folders in Exchange make searching for items in multiple folders a little more easier and/or allows you to group and find email with certain properties easier eg things like Unread email, Flagged for followup etc. Outlook 2010 makes use of these features for To-Do list etc. One useful search folder that gets created by Outlook 2010 when its used against a Exchange 2010 server is the AllItems search folder. eg this one&lt;br /&gt;&lt;br /&gt;&lt;img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJUAAACnCAIAAACXcom+AAALsUlEQVR4nO2d328TRx7A85fAK+IFJF56d7rqdFyle2jh0DUFGpJA6CV3LT9CKeV0J4RUHqoDHvoAQQ0P3EukFILEA3lChJCEuDQhwYQEYuLgxHYc23HstR2y/Ij3Hnz1rufXznp/zZjvR6tod3Z2drwfz+x3xt64IVt4d6Tz3/+5eFkD5OG773/QNG1dfd2QUd794yj4kwzdXzr7rv3LKn//BUQF8Tc9Pd2wvPK2reOf0P7kouzv7du3DfGk2nr4G/AnF2V/mqY1RBPFAwc7wZ9c6P4W4vnPW46BP7nQ/UViyv7mo+BPLsCf3ED/KTfV8cuhE+BPLnR/8aTa+gWMHyRD97e88vYwjN9lQ/eXzm4g82eA+Oj+VpUNmL+WDt1ftrDxFXx+JBu6v9zaxtET5v4aGhqM60aQbLRdgINU+/ua5Y8tA/fH2AScwtB/Fk38/T8fyQSeCP68wRC/8N3/7PtD2jF7BcSz0f2lchsdx2rxRzNKvP/h6zR/eDqAY5h/Wd1o+8pJf8RNmj/8L61kwIju72Vyo6nDsj+r4Ywlf4zygTK6v+fxjU/bfPBnmggKGej+goulj1tc96eRxiGMdZDHRvf3cL70p89h/kUydH8jL0of7gN/kqH7GwyVftsI/iRD9zcwW/oA/MmGwV8I/MlHlb/ffAb+JMNw/3tR+t1e8CcZur+hudLvIf6UDd3fcLj04X7wJxm6vwfh0h/An2zo/gLzpT9Wz7989/0PsIi5EPz9Ml/6qAn158l7CLAG2d+jl+/+3PQv3N+OH2GxtaiqGo1GE4lEJpPJGsgxQTIoipLP51OpFNVfMPLm4wOnwZ+s/p5G1v/SfIrhD3FZ3jT+hcVPf88W1j5tOWnTH4j0zV9oofBZywmaP7ydgT+x/M0t5ve3OuAPWSduGtPxzTpbPPI3v5hvOkj2R+xF2e2PZppWwo76bbse+XsZKzQf+tpBf0bYjuvVnKf+FuNrLW3k+AWXweMPeRk8bbQuF4/8RROvkOenK/uIJvj9sfPUfSvk8acoSrFYXFtbKxaLiqLU4i++rB7627c2/e0gdaE0tUhO3y+0X/4q8sqUFVr2t5R609YO8y9e+zPK27x5c0Uh0p1y+Euj/38Q/Lntzyhv06ZNW7Zs2blzZ3mzUCiUO1K7/gCb0Pwh8rZt29bY2NjU1LR7925jR8p9/0u+pt3/ADsQ/eVyOaO87du3Nzc3nzx5srOzs7W1FVfIF38eJsefWvXzfF69cB3aQ2tSPB1B9FcoFMqGtm7dumfPnrNnz3Z1dV29erW7u/vSpUvnzp3r7Ow03gvN/UVihabq//+p7/P7YWjOhw7FhOiv7Ka9vf3ChQu3bt26e/fuvV8ZHBwcGhoaGBi4ceNGORuXv7lIdt+BIzz+fEHehwLZ7c8U3vYXml9p3P93S/7wJ9krmzzpxBLwPHgdiM8I4uUwcpKvtDuY3v/Y8njvf7Nz6b/ubef3R3uSFl8xTddI5thPEJqWw1kTD/Bo/kwQf8TyTY9CwivaX9prcRWvPr+dzzTus9B/CuWPkZOnZFfxyF94Ibu36Uv++NN7f/w1MU2sw/4zEisg/z/ZdPzHGTWwM9Duefz+8HIYRSHZPMCzz4/WW9oIn98CNvHIXzz5+uAXhO8PAjbxyl/qDcx/uoF37Q/8uYGqqmNjY319fT9W080EyXD9+vWJiQnm/W95nTZ/TQxeaDgVHfDELx5Uwz6qqvb19cVisVe/Up5byTBJpzOpVDqZTC0tJSKRhcePn9y8edPk+0vNhwjfH9SsDJ4cvGq1+RNHWwVVVa9cuVIxl88XcoqSzeai0ThjiUQWw/ORUCgcfPJ0eCQwNTV9uesy8/uDi0pT63Gbnz+46o82WnepAk5R9lf5VD2XU1ZXsysrmXA4wlhmZ+dmns1OTc38/HD8/v0Hjx8/MfEXXsghv3/E4w8fwDHGdhUB7HEbra8m+mOchZYBqYPbVPwVi0VFyZflJZPp2dAcY5mefh4MPn30KBgIjA0OjkxOBk38zUVWOT8/Ygy3Le1i5GGc1NJZiBmIh7uH0P6Q5sK5yzQP46TEomi7LL1FXMIzf9l9FvtP08vH3sXIQzwpIpvnLO+Rv/lFhTb/SXvNnvWfNE+19Z+MYt3AI3+RWOEA/fsvyBu/AqNB0HYx8tDOxW5nxMy0DHXrL5pYpz3/ANjBI39LKfj+rit45C+5WkJ+Pw78OYJH/jJKCfn9OPDnCB75yxZLyO/nEOMXPIqj4U10ID4e+VPWSsjvV9n8/i74K+ORv/yr0rGT4M95vPK3XjrO7c/Yi5oO4Iibjl4iofHIX0EtHf/G/P5XSdGqTeD3RZ6U9wEh/CF1smSrhtinnpDeH/HY94f68QftT3R/Gl/84tzFkQD//QF2AH9yA/7kBvzJjf/+8DGcJRwMWOxUwy+E8GfnBTjrj7NYcQSDP2pRjJJF9mf49xJrxeJaoVBMpTLJ5EoikYrFlxejSwsL8YWF+Oxs2MXxH214h6cQR4TGzMQyiadmbBJPSquhlxD97frkk7a2tqNHjhCXM2fOXLt27WUk5u78tUYyYTOFuIlkpm3STsHO7zZEf6dPn77a3d1Lob+/f3h42El/SJ2Ibaty4fAU5EBa+2MnsjfZJ/WxCRL9Xbx4sb+//x6FkZGR0dFRj/zRdhFTGP6IxXL6M23QtLp5ANFfT0/P4ODgzxTGx8fHx8e99ldbb0m73MTmYiqeeApiNs8QNH4xriPXGkkhdl9Ec6bXmtET4rvYFfAMor/du3Z1dHR8e+oUcTl//vz1n35yrP35gi/X2g38j188xq+G4hL+xy+AHfyPXwA7CBG/+BsCGOEZsVjN4Cr+xy/sQZjH2PEnTvzp5/wL+LOE//ELw5/p4A9PIQ7yiENGxi72OA+5gpaKRbLhm1Yh+rt9+3YgEJigEAwGg8GgK/PXxKtfWXcjhTMzrWJatT/TmiMr9tuuEPEL7XIgXhnvffalYZTD3mX8S3yT4edln5EtuwaE+/yW8cJq9kc7ir+xMq4yjxKeNlobcvjj7xt51m3642l/pmc0fZNxIq4/rab4hVamMQ+7/6RlJp4IL419RlqxWq347w+wA/iTG/AnN+BPbvz311BNDa+B5yg7MYLICOHPWCGXLjT4A38iIrQ/fBSFDNSMh+DpmkYez+Gb+LosCOGPeP/D12mjYLZRzhR8RQqE8GesEN5QjG0Oz6NZtEUrE6+JFAjtD6mrI/5oZdJOKjhy+HOw/XGWKQvi+tO4Z4EZPSF+Z6WVWdll/Rr6if/+ADuAP7kBf3ID/uRGCH9ITEHEamRByy9dhMLGf3+cI2jwR0QsfwzAHxFx/REHakg3i3e8ptNjtIGgpPjvT6NoQNaJLvE8nCmcnbb4VPyVfzx1ZSWTSqWXl5PPnoUYy9TUzOTkk7GxiQejDwfuDTkWfzImsWhGOVubhvlDjpWUsr9isViWl0ymEolkPJ6YmppmLJOTwbHxiUDgl6Hh0bsD933zZykPrf1Jjaqqvb29sVhMUcq/XLySTq+kUulweJ6xhEJzs6EXz5/Pzsw8f/p05uHDsZ6eHifjTzt9IzEFaaP11H8GAoHe3t7LXZdrXnp6eu7cuePw+A9JpGnGb5z4gURzddB5apqmqmo0Gk0kEplMJmsgxwTJoChKPp+H+RcfYPgztQj+/Af8yQ34kxsh/BHDEP7XIHsMYgf//ZmOHwAGYvmrAP44EdofbWxn3NSqB3amw8E6w39/Gn0YXllHKo2PxImH1M0kCwMh/FXgnG2h+UMOAX8C+WOkgD9R7n/gzyr++9PMxn8195/4IfWHEP48APzJ56/uG5/mmb+83+2vXgF/ciOEP3b8AjDw35/p+MEU9zKLj1j+KoA/ToT2R5wURcZ2SDY8D6PMOghN/fen8c1fm86/sPNwHiUdQvir4LgJnnKk5r32RzxELvz3Zxp/OtJ/Gm+WjKOkw39/mvX5a/48mpk5qeVpgvgDagb8yY03/v4HXW+W2I9/EuUAAAAASUVORK5CYII=" alt="" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is a search folder that gets created in the NON_IPM_Subtree folder and essentially allows you to do a generic search of all the folders within a Mailbox. This can be useful in a powershell script if you do need to enumerate every item within a mailbox to use the Allitems search folder you first need to do a search for this search folder in the Mailbox Root and then you can use some normal findItems enumeration code.&lt;br /&gt;&lt;br /&gt;To filter a findfolders operation to only return search folders you can use the PR_Folder_Type extended property if this property is set to 2 then you know the folder is a search folder&lt;br /&gt;&lt;br /&gt;$PR_FOLDER_TYPE = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(13825,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The following sample script shows how to return items that where received in January 2011 in all folders within a mailbox using the AllItems search folder with an AQS query. I've put a download of the code &lt;a href="http://msgdev.mvps.org/exdevblog/allitemsSearch.zip"&gt;here&lt;/a&gt; the script itself looks like&lt;br /&gt;&lt;br /&gt;$AqsString = "System.Message.DateReceived:01/01/2011..01/31/2011"&lt;br /&gt;$MailboxName = "domain.com"&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)&lt;br /&gt;$service.Credentials = New-Object System.Net.NetworkCredential("user@domain.com","passwod")&lt;br /&gt;&lt;br /&gt;$service.AutodiscoverUrl($MailboxName,{$true})&lt;br /&gt;$PR_FOLDER_TYPE = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(13825,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);&lt;br /&gt;&lt;br /&gt;"Checking : " + $MailboxName&lt;br /&gt;$folderidcnt = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)&lt;br /&gt;$fvFolderView =  New-Object Microsoft.Exchange.WebServices.Data.FolderView(1000)&lt;br /&gt;$fvFolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Shallow;&lt;br /&gt;$sf1 = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo($PR_FOLDER_TYPE,"2")&lt;br /&gt;$sf2 = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,"allitems")&lt;br /&gt;$sfSearchFilterCol = new-object  Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And)&lt;br /&gt;$sfSearchFilterCol.Add($sf1)&lt;br /&gt;$sfSearchFilterCol.Add($sf2)&lt;br /&gt;$fiResult = $Service.FindFolders($folderidcnt,$sfSearchFilterCol,$fvFolderView)&lt;br /&gt;$fiItems = $nulll&lt;br /&gt;$ItemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)&lt;br /&gt;if($fiResult.Folders.Count -gt 0){&lt;br /&gt;  $fiResult.Folders[0].DisplayName&lt;br /&gt;  do{&lt;br /&gt;      $fiItems = $fiResult.Folders[0].findItems($AqsString,$ItemView)&lt;br /&gt;      $ItemView.offset += $fiItems .Items.Count&lt;br /&gt;      foreach($Item in $fiItems.Items){&lt;br /&gt;          $Item.Subject&lt;br /&gt;      }&lt;br /&gt;  }while($fiItems .MoreAvailable -eq $true)&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-7868428038425123531?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/7868428038425123531/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=7868428038425123531' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7868428038425123531'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7868428038425123531'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/08/using-allitems-search-folder-from.html' title='Using the AllItems Search folder from Outlook 2010 on Exchange 2010 with Powershell and the EWS Managed API'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-4301254865199288065</id><published>2011-07-20T21:40:00.006+10:00</published><updated>2011-07-20T22:33:19.171+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Using Autodiscover in powershell with the EWS Managed API and Exchange 2010 and hosted Orgs</title><content type='html'>When it comes to scripting Exchange autodiscover can be a great source for all types of configuration information about an Exchange mailbox and in 2010 it now returns a lot more information about a users mailbox. The EWS Managed API 1.1 provides some new objects that allows a more granular use of Autodiscover which can be helpful in different situations for example during migrations where DNS records for autodiscover may not exist or point to different server etc.&lt;br /&gt;&lt;br /&gt;To look at one example lets take Office365 if you want to connect to mailboxes in the Exchange Online cloud using EWS but DNS isn't setup your hosted domain for autodiscover you could use the following script to discover the EWS URL to use.&lt;br /&gt;&lt;br /&gt;$mailbox = "glen@mydomain.inthecloudblah.com"&lt;br /&gt;[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true }&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$adAutoDiscoverService = New-Object Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010);&lt;br /&gt;$uri=[system.URI] "https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc"&lt;br /&gt;$adAutoDiscoverService.Url = $uri&lt;br /&gt;$adAutoDiscoverService.Credentials = New-Object System.Net.NetworkCredential("username","password")&lt;br /&gt;$adAutoDiscoverService.EnableScpLookup = $false;&lt;br /&gt;$adAutoDiscoverService.RedirectionUrlValidationCallback = {$true};&lt;br /&gt;$adAutoDiscoverService.PreAuthenticate = $true;&lt;br /&gt;$UserSettings = new-object Microsoft.Exchange.WebServices.Autodiscover.UserSettingName[] 1&lt;br /&gt;$UserSettings[0] =  [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::ExternalEwsUrl&lt;br /&gt;$adResponse = $adAutoDiscoverService.GetUserSettings($mailbox , $UserSettings);&lt;br /&gt;$adResponse.Settings[[Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::ExternalEwsUrl]&lt;br /&gt;&lt;br /&gt;A few things to note about this script is first the hardcoded URL to autodiscover this means no autodiscover DNS records are needed for the email your looking up.&lt;br /&gt;&lt;br /&gt;$uri=[system.URI] "https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc"&lt;br /&gt;$adAutoDiscoverService.Url = $uri&lt;br /&gt;&lt;br /&gt;But as I've said the Autodiscover service isn't just not limited to retrieving URL's have a look at the usersettingname enumeration &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.autodiscover.usersettingname%28v=exchg.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.autodiscover.usersettingname%28v=exchg.80%29.aspx&lt;/a&gt; . With this you can do things such as use Alternate mailboxes to see if an online archive is configured.&lt;br /&gt;&lt;br /&gt;$UserSettings[0] =  [Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::AlternateMailboxes&lt;br /&gt;$adResponse = $adAutoDiscoverService.GetUserSettings($mailbox , $UserSettings);&lt;br /&gt;$adResponse.Settings[[Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::AlternateMailboxes]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$adAutoDiscoverService.EnableScpLookup = $false;&lt;br /&gt;&lt;br /&gt;Which means that the Managed API won't try an Active Directory look up of SCP records for autodiscover which can be very useful to speed up on the discovery process and help during migrations or other AD config issues.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-4301254865199288065?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/4301254865199288065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=4301254865199288065' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/4301254865199288065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/4301254865199288065'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/07/using-autodiscover-in-powershell-with.html' title='Using Autodiscover in powershell with the EWS Managed API and Exchange 2010 and hosted Orgs'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-6633175207367312320</id><published>2011-07-10T20:45:00.004+10:00</published><updated>2011-07-10T21:36:38.416+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Office365'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='ExchangeOnline'/><title type='text'>Running Exchange Online and Office365 Powershell cmdlets in C# and managed code</title><content type='html'>When you’re looking at automating Office365 and Exchange Online from managed code you need to be aware of the 2 sets of cmdlets that you may need to use depending on the tasks that your trying to perform. Most of the administration of ExchangeOnline is done using remote powershell where Exchange Online provides a subset of the normal on-premise Exchange 2010 SP1 cmdlets. The other cmdlet set to be aware of is the MSOnline powershell module which you need download and install &lt;a href="http://onlinehelp.microsoft.com/en-us/office365-enterprises/hh124998.aspx"&gt;http://onlinehelp.microsoft.com/en-us/office365-enterprises/hh124998.aspx&lt;/a&gt;. The MSOnline module contains cmdlets to allow administration of the wider Office365 service and perform more of the directory/service and service provider functions more akin to Active directory management in a on premise environment (eg adding users to groups etc).&lt;br /&gt;&lt;br /&gt;So when using this from Managed code to use Remote powershell against Exchange Online you use the  standard code you would use against an on-premise Exchange 2010 deployment against the endpoint https://ps.outlook.com.  With the Office365 MSOnline module you need to load this into a runspace and then firstly use the Connect-MsolService cmdlet to connect to and authenticate against Office365. Then you execute as per normal the desired cmdlets.&lt;br /&gt;&lt;br /&gt;Here's some sample code the first sample uses remote powershell to connect to ExchangeOnline.&lt;br /&gt;&lt;br /&gt;System.Security.SecureString secureString = new System.Security.SecureString();&lt;br /&gt;string myPassword = "password";&lt;br /&gt;foreach (char c in myPassword)&lt;br /&gt;secureString.AppendChar(c);&lt;br /&gt;PSCredential credential = new PSCredential("glen@domain.com", secureString);&lt;br /&gt;WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("https://ps.outlook.com/PowerShell-LiveID?PSVersion=2.0"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);&lt;br /&gt;connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;&lt;br /&gt;connectionInfo.SkipCACheck = true;&lt;br /&gt;connectionInfo.SkipCNCheck = true;&lt;br /&gt;&lt;br /&gt;connectionInfo.MaximumConnectionRedirectionCount = 4;&lt;br /&gt;Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);&lt;br /&gt;runspace.Open();&lt;br /&gt;// Make a Get-Mailbox requst using the Server Argument&lt;br /&gt;Command gmGetMailbox = new Command("get-mailbox");&lt;br /&gt;gmGetMailbox.Parameters.Add("ResultSize", "Unlimited");&lt;br /&gt;Pipeline plPileLine = runspace.CreatePipeline();&lt;br /&gt;plPileLine.Commands.Add(gmGetMailbox);&lt;br /&gt;Collection&lt;psobject&gt; RsResultsresults = plPileLine.Invoke();&lt;br /&gt;Dictionary&lt;string, psobject=""&gt; gmResults = new Dictionary&lt;string, psobject=""&gt;();&lt;br /&gt;foreach (PSObject obj in RsResultsresults)&lt;br /&gt;{&lt;br /&gt;gmResults.Add(obj.Members["WindowsEmailAddress"].Value.ToString(), obj);  &lt;br /&gt;}&lt;br /&gt;plPileLine.Stop();&lt;br /&gt;plPileLine.Dispose();&lt;br /&gt;&lt;br /&gt;This second example loads the MSOnline powershell module into a runspace&lt;br /&gt;&lt;br /&gt;InitialSessionState iss = InitialSessionState.CreateDefault();&lt;br /&gt;iss.ImportPSModule(new[] { "MSOnline" });&lt;br /&gt;using (Runspace psRunSpace = RunspaceFactory.CreateRunspace(iss))&lt;br /&gt;{&lt;br /&gt;       psRunSpace.Open();&lt;br /&gt;       using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create())&lt;br /&gt;       {&lt;br /&gt;         powershell.Runspace = psRunSpace;&lt;br /&gt;         Command connect = new Command("Connect-MsolService");&lt;br /&gt;         System.Security.SecureString secureString = new System.Security.SecureString();&lt;br /&gt;         string myPassword = "password";&lt;br /&gt;         foreach (char c in myPassword)&lt;br /&gt;           secureString.AppendChar(c);&lt;br /&gt;&lt;br /&gt;         connect.Parameters.Add("Credential", new PSCredential("glen@domain.com", secureString));&lt;br /&gt;         powershell.Commands.AddCommand(connect);&lt;br /&gt;         Collection&lt;psobject&gt; results = null;&lt;br /&gt;         Collection&lt;errorrecord&gt; errors = null;&lt;br /&gt;         results = powershell.Invoke();&lt;br /&gt;         errors = powershell.Streams.Error.ReadAll();&lt;br /&gt;         powershell.Commands.Clear();&lt;br /&gt;         Command getuser = new Command("Get-MsolUser");&lt;br /&gt;         getuser.Parameters.Add("MaxResults", 100);&lt;br /&gt;         powershell.Commands.AddCommand(getuser);&lt;br /&gt;         results = null;&lt;br /&gt;         errors = null;&lt;br /&gt;         results = powershell.Invoke();&lt;br /&gt;       }&lt;br /&gt;     }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/errorrecord&gt;&lt;/psobject&gt;&lt;/string,&gt;&lt;/string,&gt;&lt;/psobject&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-6633175207367312320?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/6633175207367312320/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=6633175207367312320' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6633175207367312320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6633175207367312320'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/07/running-exchange-online-and-office-365.html' title='Running Exchange Online and Office365 Powershell cmdlets in C# and managed code'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-5891028710074423492</id><published>2011-06-29T21:26:00.003+10:00</published><updated>2011-06-29T21:41:21.558+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Transport Agent'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2007'/><title type='text'>Processing BCC's in Exchange Transport Agents</title><content type='html'>One of the most important learning points when thinking about programing or designing Transport agents is to understand the different between a P1 (Delivery Envelope) and P2 (Display Envelope)&lt;br /&gt;&lt;br /&gt;The P1 (Delivery Envelope) contains the recipient To and From information that is transmitted to the MTA server be it Exchange or  any other SMTP server in the SMTP conversation and is the actual information that will be used for delivery of the message. Eg the Evaluating MTA will only examine the P1 recipients to determine what recipients a message would be delivered to.&lt;br /&gt;&lt;br /&gt;The P2(Display Envelope) contains all the information that that the user will see when they receive the message this includes the From, To ,CC and Subject of a message. The important point to understand is that the MTA that is processing the message doesn’t look at these headers to determine whom to deliver the message to.&lt;br /&gt;&lt;br /&gt;BCC’s&lt;br /&gt;&lt;br /&gt;One of the things that confuses a lot of people when they look at messages via an API or within an Transport Agent is that most API’s include the ability to set and get BCC address’s but they will always appear blank when you attempt to read them for example when a message is passing through the transport pipeline. The simple explanation for this is if you have understood about P1 and P2 recipients is that BCC’s when a message is submitted become P1 recipients of the message for the first MTA to process but they are never added to the P2 envelope. From the MTA’s perspective because delivery of TO, CC or BCC are treated exactly the same these elements are merely display information and the MTA just treats these recipients as another RCPT TO entry.  To detect BCC in a Transport Agent you can do two things the first is reconcile the P1 Recipients against the P2 Recipients if you find a P1 recipient that doesn’t have a matching P2 entry then you can assume that this is either a BCC or potentially an alternate or journal recipient.  The other way is to look at the Microsoft.Exchange.Transport.RecipientP2Type &lt;a href="http://msdn.microsoft.com/en-us/library/aa579279%28EXCHG.140%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa579279%28EXCHG.140%29.aspx&lt;/a&gt;  EnvelopeRecipient.Properties Property this returns an Integer that tells you what type of recipient each P1 envelope entry is.&lt;br /&gt;&lt;br /&gt;For example&lt;br /&gt;&lt;br /&gt;foreach (EnvelopeRecipient envelopeRecp in QueuedMessage.MailItem.Recipients) {&lt;br /&gt;    object RecpType = null;&lt;br /&gt;    if (envelopeRecp.Properties.TryGetValue("Microsoft.Exchange.Transport.RecipientP2Type",out RecpType))&lt;br /&gt;    {&lt;br /&gt;        switch((Int32)RecpType){&lt;br /&gt;            case 1 : // Process To&lt;br /&gt;                break;&lt;br /&gt;            case 2 : // Process CC&lt;br /&gt;                break;&lt;br /&gt;            case 3 : // Process BCC&lt;br /&gt;                break;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-5891028710074423492?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/5891028710074423492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=5891028710074423492' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/5891028710074423492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/5891028710074423492'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/06/processing-bccs-in-exchange-transport.html' title='Processing BCC&apos;s in Exchange Transport Agents'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-1057191271151708806</id><published>2011-05-14T10:51:00.007+10:00</published><updated>2011-05-15T22:25:58.183+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Classifications'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Sending a message with a classification in EWS in C# and Powershell</title><content type='html'>Message classifications have been around since Exchange 2007 and are a feature of Exchange that allows you to setup your email system to add classification to messages to comply with e-mail policies and regulatory responsibilities that Governments and other bodies may require of an organization. If you want to set a message classification on a Message your sending pro-grammatically via EWS you need to first find out what the GUID of the classification you want to set is. There are a few ways of doing this the easiest is using the Get-MessageClassification cmdlet &lt;a href="http://technet.microsoft.com/en-us/library/aa996911.aspx"&gt;http://technet.microsoft.com/en-us/library/aa996911.aspx&lt;/a&gt; the value you will need for your app or script is the ClassificationID which represents the PidLidClassificationGuid Mapi property which if you’re playing around with Transport Agents this gets converted into the x-ms-exchange-organization-classification x-header. You can also grab it out of your classification xml file if you have deployed it to Outlook.&lt;br /&gt;&lt;br /&gt;All the properties that relate to classification are documented in &lt;a href="http://msdn.microsoft.com/en-us/library/ee217686%28v=EXCHG.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/ee217686%28v=EXCHG.80%29.aspx&lt;/a&gt;. At the most basic level if you want to set a classification on a message your sending you need to set the following two properties on that message.&lt;br /&gt;&lt;br /&gt;PidLidClassificationGuid which you set to the GUID of the classification you want applied to the message&lt;br /&gt;&lt;br /&gt;PidLidClassified which is a Boolean that tells the Exchange this message is classified.&lt;br /&gt;&lt;br /&gt;With the EWS Managed API in C# this look like&lt;br /&gt;&lt;br /&gt;EmailMessage emEmailMessage = new EmailMessage(service);&lt;br /&gt;emEmailMessage.ToRecipients.Add("user@domaim.com");&lt;br /&gt;emEmailMessage.Subject = "test Classify";&lt;br /&gt;emEmailMessage.Body = new MessageBody("test");&lt;br /&gt;ExtendedPropertyDefinition PidLidClassificationGuid = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, 34232, MapiPropertyType.String);&lt;br /&gt;emEmailMessage.SetExtendedProperty(PidLidClassificationGuid, "e67e794b-f6d1-4c8f-9f63-1118d21dafa6");&lt;br /&gt;ExtendedPropertyDefinition PidLidClassified = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common,34229, MapiPropertyType.Boolean);&lt;br /&gt;emEmailMessage.SetExtendedProperty(PidLidClassified, true);&lt;br /&gt;emEmailMessage.SendAndSaveCopy();&lt;br /&gt;&lt;br /&gt;In Powershell it looks like&lt;br /&gt;&lt;br /&gt;$MailboxName = "user@domain.com"&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)&lt;br /&gt;#$service.Credentials = New-Object System.Net.NetworkCredential("glen@domain.com","password")&lt;br /&gt;$service.AutodiscoverUrl($MailboxName,{$true})&lt;br /&gt;$message = New-Object Microsoft.Exchange.WebServices.Data.EmailMessage($service)&lt;br /&gt;$message.Subject = "Test"&lt;br /&gt;$message.Body = "Test 123"&lt;br /&gt;$message.ToRecipients.Add("user@domain.com")&lt;br /&gt;$PidLidClassificationGuid = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Common, 34232,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String);&lt;br /&gt;$message.SetExtendedProperty($PidLidClassificationGuid, "e67e794b-f6d1-4c8f-9f63-1118d21dafa6");&lt;br /&gt;$PidLidClassified = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Common,34229,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Boolean);&lt;br /&gt;$message.SetExtendedProperty($PidLidClassified, $true);&lt;br /&gt;$message.Send.Invoke()&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-1057191271151708806?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/1057191271151708806/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=1057191271151708806' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/1057191271151708806'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/1057191271151708806'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/05/sending-message-with-classification-in.html' title='Sending a message with a classification in EWS in C# and Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-3699985326737106829</id><published>2011-05-09T21:10:00.008+10:00</published><updated>2011-05-09T21:52:27.832+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Making use of the PidTagStartDateEtc to calculate the age of an object for Achive and Retention policies</title><content type='html'>When your dealing with Archive and Retention policies in Exchange 2010 one of the important questions to ask is what property is used to calculate the age of an Item. While it might be tempting to use some of the easy to get to datetime properties the important property to use in relation to Archive and Retention policies is the PidTagStartDateEtc property which is documented in &lt;a href="http://msdn.microsoft.com/en-us/library/ee179537%28v=exchg.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/ee179537%28v=exchg.80%29.aspx.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So as stated this is a composite property with the first 4 bytes belonging to the default retention period if it has been applied then the final 8 bytes gives the UTC Datetime from which the Message object's age is calculated. The following is a quick sample of how to extract this datetime from that  property using the EWS Managed API.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;ExtendedPropertyDefinition PidTagStartDateEtc = new ExtendedPropertyDefinition(12315, MapiPropertyType.Binary);&lt;br /&gt;Object StartDate = null;&lt;br /&gt;itItem.TryGetProperty(PidTagStartDateEtc, out StartDate);&lt;br /&gt;long fileTime = BitConverter.ToInt64((Byte[])StartDate, 4);&lt;br /&gt;DateTime ItemAge = DateTime.FromFileTime(fileTime);&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-3699985326737106829?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/3699985326737106829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=3699985326737106829' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3699985326737106829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3699985326737106829'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/05/making-use-of-pidtagstartdateetc-to.html' title='Making use of the PidTagStartDateEtc to calculate the age of an object for Achive and Retention policies'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-7761839437771726249</id><published>2011-05-04T19:33:00.003+10:00</published><updated>2011-05-04T19:40:10.998+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Office 365'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Online'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Article on using EWS to search mailboxes</title><content type='html'>Just a quick note to let everyone know who is interested in reading more about the search capabilities of Exchange Web Services against Exchange Online (Office 365) and Exchange 2010 Check out my article that's just been published on MSDN &lt;a href="http://msdn.microsoft.com/en-us/library/hh148195%28v=EXCHG.140%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/hh148195%28v=EXCHG.140%29.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-7761839437771726249?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/7761839437771726249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=7761839437771726249' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7761839437771726249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7761839437771726249'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/05/article-on-using-ews-to-search.html' title='Article on using EWS to search mailboxes'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-8344290701383128621</id><published>2011-04-25T20:06:00.005+10:00</published><updated>2011-10-29T13:53:12.496+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Search'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Using EWS to calculate the age of Items and affect of archive and retention policies in Exchange 2010</title><content type='html'>While there are plenty of cmdlets within the Exchange Management Shell to calculate the Mailbox and Folder sizes and even Item sizes within public folders there is no cmdlets you can currently use to look at the age of the content within a mailbox to see how old it is and what affect an retention policy may have for example you may want to know how much data will be shifted to an archive store(Search-Mailbox kind of does it but...). To look at Mailbox Content the EWS Managed API provides a easy entry point and the flexibility to do this . On Exchange 2010 to scan for content between a particular date range using a Content Index query via Exchange Search is the quickest and most efficient way of querying this data. The EWS Managed API allows you to perform a CI search via Exchange Search using the AQS querystring overload parameter of the FindItems method see &lt;a href="http://msdn.microsoft.com/en-us/library/ee693615%28v=exchg.140%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/ee693615%28v=exchg.140%29.aspx&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;With AQS the operator .. can be used to search between a range of values for example you could use it to search for Messages between 5 and 10 MB using a AQS String like System.Size:1mb..5mb. When searching for age based content you want to search for items between a particular date range for example to search for items 3 years old you could use 01/01/1990..01/01/2008.&lt;br /&gt;&lt;br /&gt;What I've done is create a EWS Managed API script that put this all together it firstly does a query to get the folder hierarchy adding a few other useful properties like the folderpath and the current folder size then using measure-object this sums a collection of folder items based on the Item size. The script produces a CSV file of all the folders in a mailbox that contain items with the Daterange and what the size of those items is and what percentage of the total size of the mailbox folder is the output should look like&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/-hs5aNUXo5YU/TbVZmQQp-aI/AAAAAAAAADE/ZHhJu2JbsOI/s1600/sizeSnap.PNG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5599480225439807906" src="http://2.bp.blogspot.com/-hs5aNUXo5YU/TbVZmQQp-aI/AAAAAAAAADE/ZHhJu2JbsOI/s400/sizeSnap.PNG" style="cursor: pointer; height: 103px; width: 400px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;With this script the following two variables control the data range for the AQS query and the mailboxes to access&lt;br /&gt;&lt;br /&gt;$Range = "01/01/1990..01/01/2008"&amp;nbsp; &lt;br /&gt;$MailboxName = "user@domain.com"&lt;br /&gt;&lt;br /&gt;I've put a download of this &lt;a href="http://msgdev.mvps.org/exdevblog/mbagereport.zip"&gt;script &lt;/a&gt;here the code looks like&lt;br /&gt;&lt;br /&gt;&lt;link href="http://www.thecomplex.plus.com/styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css"&gt;&lt;/link&gt;&lt;br /&gt;&lt;div class="dp-highlighter" id="hlDiv"&gt;&lt;div class="bar"&gt;&lt;/div&gt;&lt;ol class="dp-rb" start="1"&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$Range&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"01/01/1990..01/01/2008"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"user@domain.com"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$AQSString&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"System.Message.DateReceived:"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$Range&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$rptCollection&lt;/span&gt;&amp;nbsp;=&amp;nbsp;@()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="keyword"&gt;function&lt;/span&gt;&amp;nbsp;ConvertToString(&lt;span class="variable"&gt;$ipInputString&lt;/span&gt;){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Val1Text&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;""&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;for&lt;/span&gt;&amp;nbsp;(&lt;span class="variable"&gt;$clInt&lt;/span&gt;=0;&lt;span class="variable"&gt;$clInt&lt;/span&gt;&amp;nbsp;-lt&amp;nbsp;&lt;span class="variable"&gt;$ipInputString&lt;/span&gt;.length;&lt;span class="variable"&gt;$clInt&lt;/span&gt;++){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$Val1Text&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$Val1Text&lt;/span&gt;&amp;nbsp;+&amp;nbsp;[Convert]::ToString([Convert]::ToChar([Convert]::ToInt32(&lt;span class="variable"&gt;$ipInputString&lt;/span&gt;.Substring(&lt;span class="variable"&gt;$clInt&lt;/span&gt;,2),16)))&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$clInt&lt;/span&gt;++&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;return&lt;/span&gt;&amp;nbsp;&lt;span class="variable"&gt;$Val1Text&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$dllpath&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"C:\Program&amp;nbsp;Files\Microsoft\Exchange\Web&amp;nbsp;Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;[void][Reflection.Assembly]::LoadFile(&lt;span class="variable"&gt;$dllpath&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="comment"&gt;#$service.Credentials&amp;nbsp;=&amp;nbsp;New-Object&amp;nbsp;System.Net.NetworkCredential("username","password")&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$windowsIdentity&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[System.Security.Principal.WindowsIdentity]::GetCurrent()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$sidbind&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;"LDAP://&amp;lt;SID="&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$windowsIdentity&lt;/span&gt;.user.Value.ToString()&amp;nbsp;+&amp;nbsp;&lt;span class="string"&gt;"&amp;gt;"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$aceuser&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[ADSI]&lt;span class="variable"&gt;$sidbind&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$service&lt;/span&gt;.AutodiscoverUrl(&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;,{&lt;span class="variable"&gt;$true&lt;/span&gt;})&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$PR_FOLDER_TYPE&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(13825,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="string"&gt;"Checking&amp;nbsp;:&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$folderidcnt&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.FolderView(1000)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;.Traversal&amp;nbsp;=&amp;nbsp;[Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$psPropertySet&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$PR_MESSAGE_SIZE_EXTENDED&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3592,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Long);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$PR_DELETED_MESSAGE_SIZE_EXTENDED&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26267,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Long);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$PR_Folder_Path&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26293,&amp;nbsp;[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$psPropertySet&lt;/span&gt;.Add(&lt;span class="variable"&gt;$PR_MESSAGE_SIZE_EXTENDED&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$psPropertySet&lt;/span&gt;.Add(&lt;span class="variable"&gt;$PR_Folder_Path&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;.PropertySet&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$psPropertySet&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$sfSearchFilter&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo(&lt;span class="variable"&gt;$PR_FOLDER_TYPE&lt;/span&gt;,&lt;span class="string"&gt;"1"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$Service&lt;/span&gt;.FindFolders(&lt;span class="variable"&gt;$folderidcnt&lt;/span&gt;,&lt;span class="variable"&gt;$sfSearchFilter&lt;/span&gt;,&lt;span class="variable"&gt;$fvFolderView&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="keyword"&gt;foreach&lt;/span&gt;(&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class="variable"&gt;$fiResult&lt;/span&gt;.Folders){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="string"&gt;"Processing&amp;nbsp;:&amp;nbsp;"&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;.displayName&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$TotalItemCount&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$TotalItemCount&lt;/span&gt;&amp;nbsp;+&amp;nbsp;&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;.TotalCount;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$FolderSize&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$FolderSizeValue&lt;/span&gt;&amp;nbsp;=&amp;nbsp;0&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;.TryGetProperty(&lt;span class="variable"&gt;$PR_MESSAGE_SIZE_EXTENDED&lt;/span&gt;,[ref]&amp;nbsp;&lt;span class="variable"&gt;$FolderSize&lt;/span&gt;))&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$FolderSizeValue&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Int64]&lt;span class="variable"&gt;$FolderSize&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$foldpathval&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;.TryGetProperty(&lt;span class="variable"&gt;$PR_Folder_Path&lt;/span&gt;,[ref]&amp;nbsp;&lt;span class="variable"&gt;$foldpathval&lt;/span&gt;))&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$binarry&lt;/span&gt;&amp;nbsp;=&amp;nbsp;[Text.Encoding]::UTF8.GetBytes(&lt;span class="variable"&gt;$foldpathval&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$hexArr&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$binarry&lt;/span&gt;&amp;nbsp;|&amp;nbsp;&lt;span class="builtin"&gt;ForEach-Object&lt;/span&gt;&amp;nbsp;{&amp;nbsp;&lt;span class="variable"&gt;$_&lt;/span&gt;.ToString(&lt;span class="string"&gt;"X2"&lt;/span&gt;)&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$hexString&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$hexArr&lt;/span&gt;&amp;nbsp;-join&amp;nbsp;&lt;span class="string"&gt;''&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$hexString&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$hexString&lt;/span&gt;.Replace(&lt;span class="string"&gt;"FEFF"&lt;/span&gt;,&amp;nbsp;&lt;span class="string"&gt;"5C00"&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$fpath&lt;/span&gt;&amp;nbsp;=&amp;nbsp;ConvertToString(&lt;span class="variable"&gt;$hexString&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$fiFindItems&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$ItemView&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="builtin"&gt;New-Object&lt;/span&gt;&amp;nbsp;Microsoft.Exchange.WebServices.Data.ItemView(1000)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$psPropertySet1&lt;/span&gt;&amp;nbsp;=&amp;nbsp;new-object&amp;nbsp;Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$psPropertySet1&lt;/span&gt;.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::Size)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$ItemView&lt;/span&gt;.PropertySet&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$itemCollection&lt;/span&gt;&amp;nbsp;=&amp;nbsp;@()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;do{&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$fiFindItems&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;.findItems(&lt;span class="variable"&gt;$AQSString&lt;/span&gt;,&lt;span class="variable"&gt;$ItemView&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$ItemView&lt;/span&gt;.offset&amp;nbsp;+=&amp;nbsp;&lt;span class="variable"&gt;$fiFindItems&lt;/span&gt;.Items.Count&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;foreach&lt;/span&gt;(&lt;span class="variable"&gt;$Item&lt;/span&gt;&amp;nbsp;&lt;span class="keyword"&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class="variable"&gt;$fiFindItems&lt;/span&gt;.Items){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$rptobject&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="string"&gt;""&lt;/span&gt;&amp;nbsp;|&amp;nbsp;select&amp;nbsp;Size&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$rptobject&lt;/span&gt;.Size&amp;nbsp;=&amp;nbsp;&lt;span class="variable"&gt;$Item&lt;/span&gt;.Size&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$itemCollection&lt;/span&gt;&amp;nbsp;+=&lt;span class="variable"&gt;$rptobject&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;span class="keyword"&gt;while&lt;/span&gt;(&lt;span class="variable"&gt;$fiFindItems&lt;/span&gt;.MoreAvailable&amp;nbsp;-eq&amp;nbsp;&lt;span class="variable"&gt;$true&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$outObj&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$itemCollection&lt;/span&gt;&amp;nbsp;|&amp;nbsp;&lt;span class="builtin"&gt;Measure-Object&lt;/span&gt;&amp;nbsp;Size&amp;nbsp;-Sum&amp;nbsp;-Average&amp;nbsp;-Min&amp;nbsp;-Max&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="keyword"&gt;if&lt;/span&gt;(&lt;span class="variable"&gt;$outObj&lt;/span&gt;&amp;nbsp;-ne&amp;nbsp;&lt;span class="variable"&gt;$null&lt;/span&gt;){&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="builtin"&gt;Add-Member&lt;/span&gt;&amp;nbsp;-InputObject&amp;nbsp;&lt;span class="variable"&gt;$outObj&lt;/span&gt;&amp;nbsp;-MemberType&amp;nbsp;NoteProperty&amp;nbsp;-Name&amp;nbsp;Mailbox&amp;nbsp;-Value&amp;nbsp;&lt;span class="variable"&gt;$MailboxName&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="builtin"&gt;Add-Member&lt;/span&gt;&amp;nbsp;-InputObject&amp;nbsp;&lt;span class="variable"&gt;$outObj&lt;/span&gt;&amp;nbsp;NoteProperty&amp;nbsp;-Name&amp;nbsp;Folder&amp;nbsp;-Value&amp;nbsp;&lt;span class="variable"&gt;$ffFolder&lt;/span&gt;.DisplayName&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="builtin"&gt;Add-Member&lt;/span&gt;&amp;nbsp;-InputObject&amp;nbsp;&lt;span class="variable"&gt;$outObj&lt;/span&gt;&amp;nbsp;NoteProperty&amp;nbsp;-Name&amp;nbsp;FolderPath&amp;nbsp;-Value&amp;nbsp;&lt;span class="variable"&gt;$fpath&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="builtin"&gt;Add-Member&lt;/span&gt;&amp;nbsp;-InputObject&amp;nbsp;&lt;span class="variable"&gt;$outObj&lt;/span&gt;&amp;nbsp;NoteProperty&amp;nbsp;-Name&amp;nbsp;TotalFolderSize&amp;nbsp;-Value&amp;nbsp;&lt;span class="variable"&gt;$FolderSizeValue&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="builtin"&gt;Add-Member&lt;/span&gt;&amp;nbsp;-InputObject&amp;nbsp;&lt;span class="variable"&gt;$outObj&lt;/span&gt;&amp;nbsp;NoteProperty&amp;nbsp;-Name&amp;nbsp;DateRange&amp;nbsp;-Value&amp;nbsp;&lt;span class="variable"&gt;$Range&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class="variable"&gt;$rptCollection&lt;/span&gt;&amp;nbsp;+=&amp;nbsp;&lt;span class="variable"&gt;$outObj&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class=""&gt;}&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span class="variable"&gt;$rptCollection&lt;/span&gt;&amp;nbsp;|&amp;nbsp;select&amp;nbsp;Mailbox,Folder,FolderPath,@{label=&lt;span class="string"&gt;"FolderSize(MB)"&lt;/span&gt;;expression={[math]::Round(&lt;span class="variable"&gt;$_&lt;/span&gt;.TotalFolderSize/1MB,2)}},@{label=&lt;span class="string"&gt;"RangeSize(MB)"&lt;/span&gt;;expression={[math]::Round(&lt;span class="variable"&gt;$_&lt;/span&gt;.Sum/1MB,2)}},@{label=&lt;span class="string"&gt;"RangeCount"&lt;/span&gt;;expression={&lt;span class="variable"&gt;$_&lt;/span&gt;.Count}},@{label=&lt;span class="string"&gt;"PercentOfSize"&lt;/span&gt;;expression={&lt;span class="string"&gt;'{0:P0}'&lt;/span&gt;&amp;nbsp;-f&amp;nbsp;(&lt;span class="variable"&gt;$_&lt;/span&gt;.Sum/&lt;span class="variable"&gt;$_&lt;/span&gt;.TotalFolderSize)}}&amp;nbsp;|&amp;nbsp;export-csv&amp;nbsp;c:\temp\MbAgeReport.csv&amp;nbsp;-NoTypeInformation&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-8344290701383128621?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/8344290701383128621/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=8344290701383128621' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/8344290701383128621'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/8344290701383128621'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/04/using-ews-to-calculate-age-of-items-and.html' title='Using EWS to calculate the age of Items and affect of archive and retention policies in Exchange 2010'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-hs5aNUXo5YU/TbVZmQQp-aI/AAAAAAAAADE/ZHhJu2JbsOI/s72-c/sizeSnap.PNG' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-225899717844345288</id><published>2011-04-05T13:21:00.006+10:00</published><updated>2011-04-05T14:13:35.146+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2007'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Displaying the OOF log in a mailbox using Exchange Web Services and Powershell</title><content type='html'>&lt;div&gt;On a Exchange 2007 and 2010 when changes are made to the Out of Office setting these changes are logged into an Item sitting in the Non_IPM_Subtree folder of a mailbox which has a message class of  IPM.Microsoft.OOF.Log .&lt;br /&gt;&lt;br /&gt;The log of changes is written to the body of this message and can be useful if for any reason you need a historical record of the oof setting for a particular mailbox. For instance if someone set an inappropriate OOF message and you need some evidence of this. You could also sequence this data to get picture over a certain time period of what users had their oof set and for how long it was enabled and did it say anything useful.&lt;br /&gt;&lt;br /&gt;I've put together a script to show how to get at this log using the EWS Managed API and powershell and I've also included a parser to parse the log entries into an object to make it easier to export this data to csv or email etc.&lt;br /&gt;&lt;br /&gt;I've put a download of this script &lt;a href="http://msgdev.mvps.org/exdevblog/showooflog.zip"&gt;here&lt;/a&gt; the script itself looks like&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;$MailboxName = "user@domain"&lt;br /&gt;$rptCollection = @()&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)&lt;br /&gt;$service.TraceEnabled = $false&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()&lt;br /&gt;$sidbind = "LDAP://&amp;lt;SID=" + $windowsIdentity.user.Value.ToString() + "&amp;gt;"&lt;br /&gt;$aceuser = [ADSI]$sidbind&lt;br /&gt;# $service.Credentials = New-Object System.Net.NetworkCredential("user","password")&lt;br /&gt;$service.AutodiscoverUrl($MailboxName ,{$true})&lt;br /&gt;&lt;br /&gt;$nonipmRoot = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)&lt;br /&gt;$ivItemView = new-object Microsoft.Exchange.WebServices.Data.ItemView(2)&lt;br /&gt;$sfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.ItemSchema]::ItemClass, "IPM.Microsoft.OOF.Log")&lt;br /&gt;$psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)&lt;br /&gt;$psPropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text;&lt;br /&gt;$fiItems = $service.finditems($nonipmRoot,$sfSearchFilter,$ivItemView)&lt;br /&gt;foreach($itItem in $fiItems.Items){&lt;br /&gt;&lt;br /&gt;    $itItem.load($psPropertySet)&lt;br /&gt;    $itItem.Body.Text.Split("`r") | ForEach-Object{&lt;br /&gt;        $line = $_&lt;br /&gt;        if($line.indexof("Mailbox:")-gt 0){&lt;br /&gt;            $elen = $line.indexof("Mailbox:")&lt;br /&gt;            if($elen -gt 0){&lt;br /&gt;                $datetime = $line.SubString(1,$elen-3)&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        if($line.indexof("Mailbox:")-gt 0){&lt;br /&gt;            $slen = $line.indexof("Mailbox:")&lt;br /&gt;            $elen = $line.indexof("OofState:",$slen)&lt;br /&gt;            if($slen -gt 0){&lt;br /&gt;                $slen += 10&lt;br /&gt;                $mailbox = $line.SubString($slen,($elen-$slen)-3)&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        if($line.indexof("OofState:")-gt 0){&lt;br /&gt;            $slen = $line.indexof("OofState:")&lt;br /&gt;            $elen = $line.indexof("ExternalAudience:",$slen)&lt;br /&gt;            if($slen -gt 0){&lt;br /&gt;                $slen += 10&lt;br /&gt;                $OofState = $line.SubString($slen,($elen-$slen)-2)&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        if($line.indexof("ExternalAudience:")-gt 0){&lt;br /&gt;            $slen = $line.indexof("ExternalAudience:")&lt;br /&gt;            $elen = $line.indexof("InternalReply:",$slen)&lt;br /&gt;            if($slen -gt 0){&lt;br /&gt;                $slen += 18&lt;br /&gt;                $ExternalAudience = $line.SubString($slen,($elen-$slen)-2)&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        if($line.indexof("InternalReply:")-gt 0){&lt;br /&gt;            $slen = $line.indexof("InternalReply:")&lt;br /&gt;            $elen = $line.indexof("ExternalReply:",$slen)&lt;br /&gt;            if($slen -gt 0){&lt;br /&gt;                $slen += 15&lt;br /&gt;                $InternalReply = $line.SubString($slen,($elen-$slen)-2)&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        if($line.indexof("ExternalReply:")-gt 0){&lt;br /&gt;            $slen = $line.indexof("ExternalReply:")&lt;br /&gt;            $elen = $line.indexof("SetByLegacyClient:",$slen)&lt;br /&gt;            if($slen -gt 0){&lt;br /&gt;                $slen += 15&lt;br /&gt;                $ExternalReply = $line.SubString($slen,($elen-$slen)-2)&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        if($line.indexof("SetByLegacyClient:")-gt 0){&lt;br /&gt;            $slen = $line.indexof("SetByLegacyClient:")&lt;br /&gt;            $elen = $line.indexof("comment:")&lt;br /&gt;            if($slen -gt 0){&lt;br /&gt;                $slen += 20&lt;br /&gt;                $SetByLegacyClient = $line.SubString($slen,($elen-$slen)-3)&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        if($line.indexof("comment:")-gt 0){&lt;br /&gt;            $slen = $line.indexof("comment")&lt;br /&gt;            $elen = $line.indexof("'",$slen)&lt;br /&gt;            if($slen -gt 0){&lt;br /&gt;                $slen += 9&lt;br /&gt;                $comment = $line.SubString($slen,($elen-$slen))&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        $mbcomb = "" | select datetime,mailbox,OofState,ExternalAudience,InternalReply,ExternalReply,SetByLegacyClient,comment       &lt;br /&gt;        $mbcomb.datetime = $datetime&lt;br /&gt;        $mbcomb.mailbox = $mailbox&lt;br /&gt;        $mbcomb.OofState = $OofState&lt;br /&gt;        $mbcomb.ExternalAudience = $ExternalAudience&lt;br /&gt;        $mbcomb.InternalReply = $InternalReply&lt;br /&gt;        $mbcomb.ExternalReply = $ExternalReply&lt;br /&gt;        $mbcomb.SetByLegacyClient = $SetByLegacyClient&lt;br /&gt;        $mbcomb.comment = $comment&lt;br /&gt;        $rptCollection += $mbcomb&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;$rptCollection &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-225899717844345288?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/225899717844345288/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=225899717844345288' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/225899717844345288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/225899717844345288'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/04/displaying-oof-log-in-mailbox-using.html' title='Displaying the OOF log in a mailbox using Exchange Web Services and Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-3246233889991330490</id><published>2011-04-02T20:03:00.006+11:00</published><updated>2011-04-08T16:42:40.502+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Transport Agent'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2007'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><title type='text'>Reading custom MAPI properties in a Transport Agent</title><content type='html'>In Exchange 2007 and 2010 all mail that is sent and received must transit its way through a Hub server where if your a developer you can create a transport agent to perform additional tasks on those messages before the are passed out of your org or into a mailbox. Sometimes these tasks may involve custom mapi properties that you may have created by using customized forms in Outlook or OWA or possibly a custom EWS application. When it comes to accessing these custom properties in a Transport Agent it involves using the TNEFReader in a transport agent to parse TNEF part of a message.&lt;br /&gt;&lt;br /&gt;TNEF for those uninitiated stands for Transport Neutral Encapsulation Format which is a serialization format that Exchange uses to send the Mapi properties of a Item via email there is a protocol document that covers this &lt;a href="http://msdn.microsoft.com/en-us/library/cc425498%28v=EXCHG.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc425498%28v=EXCHG.80%29.aspx&lt;/a&gt;. What the TNEFReader does is allows a Transport Agent to parse all the different property structures and data-types contained within the TNEF data stream.&lt;br /&gt;&lt;br /&gt;One of the harder things to understand when dealing with Mapi properties is that they come in two different types. The following &lt;a href="http://msdn.microsoft.com/en-us/library/cc979184.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc979184.aspx&lt;/a&gt; page describes the difference between tagged properties and named properties. And there are different properties for different parts of a messages for instance there are Item properties for the Item, Recipient properties in the recipients collection for each recipients and attachment properties for each attachment. So when you are parsing an Item its not just as simple as reading one particular property collection (depending on what your trying to do).&lt;br /&gt;&lt;br /&gt;For custom properties these should always be named properties and for the most they will use the PS_PUBLIC_STRINGS property set (but you may have created your own custom propset GUID) and either a  long ID (LID) or String value for the PropertyName. This can all be confirmed using a Mapi Editor like MFCMapi or OutlookSpy to look at an item where this property has been set.&lt;br /&gt;&lt;br /&gt;When you have gathered all this information your ready to use the property in your Transport Agent. The first thing to do when parsing a TNEF part in a transport agent is to work out at what level or properties you want to parse eg the Message properties or the attachment properties or possibly an embedded attachments properties (an Item attachment).  The TNEFReader parses the properties in a forward direction to test if a property is a named property you use the&lt;br /&gt;&lt;br /&gt;reader.PropertyReader.IsNamedProperty&lt;br /&gt;&lt;br /&gt;If you want to check the propset GUID&lt;br /&gt;&lt;br /&gt;reader.PropertyReader.PropertyNameId.PropertySetGuid&lt;br /&gt;&lt;br /&gt;To see if this property is using a LID or String&lt;br /&gt;&lt;br /&gt;reader.PropertyReader.PropertyNameId.Kind == TnefNameIdKind.Name&lt;br /&gt;&lt;br /&gt;To demonstrate this I've put together a sample that pushes a particular custom property into a x-header which i find it useful for a number of things. I've put a download of the code &lt;a href="http://msgdev.mvps.org/exdevblog/mpagent.zip"&gt;here&lt;/a&gt; the agent looks like&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.Diagnostics;&lt;br /&gt;using Microsoft.Exchange.Data.Transport;&lt;br /&gt;using Microsoft.Exchange.Data.Mime;&lt;br /&gt;using Microsoft.Exchange.Data.ContentTypes.Tnef;&lt;br /&gt;using Microsoft.Exchange.Data.Transport.Email;&lt;br /&gt;using Microsoft.Exchange.Data.Transport.Routing;&lt;br /&gt;using Microsoft.Exchange.Data.Common;&lt;br /&gt;using System.IO;&lt;br /&gt;using Microsoft.Win32;&lt;br /&gt;using System.Reflection;&lt;br /&gt;&lt;br /&gt;namespace ExchangeRoutingAgents&lt;br /&gt;{&lt;br /&gt;   public class MapiPropAgentFactory : RoutingAgentFactory&lt;br /&gt;   {&lt;br /&gt;       public override RoutingAgent CreateAgent(SmtpServer server)&lt;br /&gt;       {&lt;br /&gt;           RoutingAgent mpAgent = new MapiPropAgent();&lt;br /&gt;           return mpAgent;&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class MapiPropAgent : RoutingAgent&lt;br /&gt;{&lt;br /&gt;   public MapiPropAgent()&lt;br /&gt;   {&lt;br /&gt;       this.OnRoutedMessage += new RoutedMessageEventHandler(MapiPropAgent_OnRoutedMessage);&lt;br /&gt;   }&lt;br /&gt;   void MapiPropAgent_OnRoutedMessage(RoutedMessageEventSource esEvtsource, QueuedMessageEventArgs qmQueuedMessage)&lt;br /&gt;   {&lt;br /&gt;       String myPropString = "myExtraInfo";&lt;br /&gt;       MimePart tnefPart = qmQueuedMessage.MailItem.Message.TnefPart;&lt;br /&gt;       if (tnefPart != null)&lt;br /&gt;       {&lt;br /&gt;           //Check the Mimeheader to see if the X-header exists&lt;br /&gt;           MimeDocument mdMimeDoc = qmQueuedMessage.MailItem.Message.MimeDocument;&lt;br /&gt;           HeaderList hlHeaderlist = mdMimeDoc.RootPart.Headers;&lt;br /&gt;           Header myPropHeader = hlHeaderlist.FindFirst(myPropString);&lt;br /&gt;           TnefReader reader = new TnefReader(tnefPart.GetContentReadStream(), 0, TnefComplianceMode.Loose);&lt;br /&gt;           while (reader.ReadNextAttribute())&lt;br /&gt;           {&lt;br /&gt;               //Find Message Level TNEF attributes&lt;br /&gt;               if (reader.AttributeTag == TnefAttributeTag.MapiProperties)&lt;br /&gt;               {&lt;br /&gt;&lt;br /&gt;                   while (reader.PropertyReader.ReadNextProperty())&lt;br /&gt;                   {&lt;br /&gt;                       if (reader.PropertyReader.IsNamedProperty)&lt;br /&gt;                       {&lt;br /&gt;                           if (reader.PropertyReader.PropertyNameId.Name == myPropString)&lt;br /&gt;                           {&lt;br /&gt;&lt;br /&gt;                               String myPropStringValue = reader.PropertyReader.ReadValueAsString();&lt;br /&gt;                               if (myPropHeader == null)&lt;br /&gt;                               {&lt;br /&gt;                                   MimeNode lhLasterHeader = hlHeaderlist.LastChild;&lt;br /&gt;                                   TextHeader nhNewHeader = new TextHeader(myPropString, myPropStringValue);&lt;br /&gt;                                   hlHeaderlist.InsertBefore(nhNewHeader, lhLasterHeader);&lt;br /&gt;                                   lhLasterHeader = null;&lt;br /&gt;                                   nhNewHeader = null;&lt;br /&gt;                               }&lt;br /&gt;                           }&lt;br /&gt;                       }&lt;br /&gt;&lt;br /&gt;                   }&lt;br /&gt;&lt;br /&gt;               }&lt;br /&gt;           }&lt;br /&gt;           reader.Dispose();&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-3246233889991330490?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/3246233889991330490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=3246233889991330490' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3246233889991330490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3246233889991330490'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/04/reading-custom-mapi-properties-in.html' title='Reading custom MAPI properties in a Transport Agent'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-3237732506706709570</id><published>2011-03-30T21:06:00.009+11:00</published><updated>2011-04-01T13:24:01.970+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Module'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Displaying Delegate Forward rule entries and removing any invalid entires with EWS and Powershell</title><content type='html'>This post follows on a little from a previous &lt;a href="http://gsexdev.blogspot.com/2011/03/dealing-with-invalid-delegates-with.html"&gt;post&lt;/a&gt; where i was talking about invalid delegates. One thing the current EWS Rule operations in Exchange 2010 and also the Get-InboxRule cmdlets can't do is that both of these wont display any information about the delegate forward rule if its been configured. Now you can tell using the delegate operation if a forward rule has been configured for a user but this still doesn't read the rule object directly. You could question why you would want to do this if that's the case and the reason is usually when your trying to diagnose why somebody maybe geting a bounce message when meeting messages are being forwarded to an invalid mailbox user (eg a deleted delegate).&lt;br /&gt;&lt;br /&gt;If you want to find what delegates the delegate rule is forwarding to you need to read these directly from the rule object.  On Exchange 2010 you can access Folder Associated Items (FAI) and the Delegate rule object. In EWS to find this you can create a searchfilter and look for the FAI item where the &lt;a href="http://msdn.microsoft.com/en-us/library/cc842177%28v=office.12%29.aspx"&gt;PR_RuleMsgProvider_W&lt;/a&gt; property is set to  "Schedule+ EMS Interface". Once there the address that a delegate is forwarded to are stored in the PidTagRuleMsgActions property which is documented in Rules protocol document &lt;a href="http://msdn.microsoft.com/en-us/library/cc463893%28v=EXCHG.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc463893%28v=EXCHG.80%29.aspx &lt;/a&gt;. Parsing this property however is not trivial basically this property is a stream of serialized MAPI properties so one property that stores other properties such as PR_DisplayName and PR_EMAIL_ADDRESS_W. Fortunately i had a bit of experience and code from the &lt;a href="http://ewsftstream.codeplex.com/"&gt;FTS Stream parser&lt;/a&gt; i wrote and with some simple adaption this code can be more or less plugged in and returns all the properties and value parsed correctly. For the purpose of reading the delegates a forwarding rule is forwarding to PR_EMAIL_ADDRESS_W is the important property.&lt;br /&gt;&lt;br /&gt;So to make this usable from Powershell I've created some cmdlets that first allows you to read the raw actions property on the delegate rule. Display any of these rules that are invalid it does this by using a EWS getdelegate operation and then comparing the valid entries retrieved with the delegate rules that exist. Then there is a unsupported remove cmdlet although the method I've used in not that bad basically what the remove does is if it finds one valid delegate in the delegate rule it forces an update of this delegate rule using an update delegate operation which will cause the delegate rule to be updated which will remove the invalid entry (as long as you have cleaned up the invalid delegates in Outlook or the other &lt;span style="font-size:85%;"&gt;Remove-MessageOps.MailboxDelegatesInvalid.Unsupported cmdlet).&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Get-MessageOps.MailboxDelegateForwardingRules: This cmdlet retrieves the MailboxDelegate Forwarding rules by finding the rules object in the associated folders collection of the Inbox and then parsing the actions MAPI property on this object. Note because of the limitation in EWS in 2007 this cmdlet will only work on Exchange 2010.&lt;br /&gt;&lt;br /&gt;Example: Get-MessageOps.MailboxDelegateForwardingRules –p $ewsprofile –identity mailbox@domain.com&lt;br /&gt;&lt;br /&gt;Get-MessageOps.MailboxDelegateInvalidForwardingRules: This cmdlet retrieves the MailboxDelegate Forwarding rules by finding the rules object in the associated folders collection of the Inbox and then parsing the actions MAPI property on this object. It then compares the entries contained in the forwarding rule to check if there is a valid delegate for this entry by using a getdelegates operation. Any users that don’t have a valid delegate entry is returned as invalid.&lt;br /&gt;Example: Remove-MailboxDelegateInvalidForwardingRules –p $ewsprofile –identity mailbox@domain.com&lt;br /&gt;&lt;br /&gt;Remove-MessageOps.MailboxDelegateInvalidForwardingRules.Unsupported: This cmdlet retrieves the MailboxDelegate Forwarding rules by finding the rules object in the associated folders collection of the Inbox and then parsing the actions MAPI property on this object. It then compares the entries contained in the forwarding rule to check if there is a valid delegate for this entry by using a getdelegates operation. If an invalid entry is found depending on the number of delegate entries the following action are taken.&lt;br /&gt;&lt;br /&gt;· If other valid entries are found a update delegate operation is performed on one these entries which should make the sever side process remove the invalid entry when the forward rule is updated.&lt;br /&gt;&lt;br /&gt;· If no other valid entries are found the rule object is deleted.&lt;br /&gt;&lt;br /&gt;Example: Remove-MessageOps.MailboxDelegateInvalidForwardingRules.Unsupported –p $ewsprofile –identity mailbox@domain.com&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;To use these cmdlets you need to download the following module &lt;a href="http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip"&gt;http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-3237732506706709570?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/3237732506706709570/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=3237732506706709570' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3237732506706709570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3237732506706709570'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/03/display-delegate-forward-rules-and.html' title='Displaying Delegate Forward rule entries and removing any invalid entires with EWS and Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-4026461205003566045</id><published>2011-03-29T14:45:00.005+11:00</published><updated>2011-03-29T16:39:09.406+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Audit'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Exchange 2010 Administrator Audit log Powershell GUI</title><content type='html'>An interesting and useful new feature of Exchange 2010 is Administrator audit logging where each time a EMS cmdlet is run in the Exchange in the EMS, EMC or ECP this is logged.  Within ECP you can do a search of the admin Audit logs and have the result emailed to you and what you receive in your inbox is an email with an a attachment called searchresult.xml. While this file contains a lot of great information there are a few problems with this format for administrators firstly is that OWA and Oultook will usually block the XML attachments so it can firstly be hard to get to the attachment.  Secondly XML isn't the most readable format when it comes to trying to intemperate what was going on especially if you search across a larger number of days.  So what I've put together is a GUI that first uses the EWS Managed API to find these any of these emails within your inbox and then gives you the option of exporting the raw xml or converting the XML to a CSV file or lastly using a separate report winform that groups the data retrieved and displays it back to the user. The later i think is a lot more useful as it lets you work more intuitively with the data and the better you can do this the more likely it is that you would spot an abnormality which is one to the purposes of auditing. eg this is what it looks like&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/-vSVS0IyIiLE/TZFrh39njkI/AAAAAAAAAC8/T3lEv7rvK48/s1600/aud.PNG"&gt;&lt;img style="cursor: pointer; width: 584px; height: 266px;" src="http://2.bp.blogspot.com/-vSVS0IyIiLE/TZFrh39njkI/AAAAAAAAAC8/T3lEv7rvK48/s320/aud.PNG" alt="" id="BLOGGER_PHOTO_ID_5589366842245746242" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Note this GUI currently only handles the Admin Audit logs not the Mailbox Audit log which are in a different format.&lt;br /&gt;&lt;br /&gt;I've put a download of this script &lt;a href="http://msgdev.mvps.org/exdevblog/ewsaudgui.zip"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-4026461205003566045?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/4026461205003566045/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=4026461205003566045' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/4026461205003566045'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/4026461205003566045'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/03/exchange-2010-administrator-audit-log.html' title='Exchange 2010 Administrator Audit log Powershell GUI'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-vSVS0IyIiLE/TZFrh39njkI/AAAAAAAAAC8/T3lEv7rvK48/s72-c/aud.PNG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-7417445414545337718</id><published>2011-03-27T21:20:00.007+11:00</published><updated>2011-03-28T13:24:03.338+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2007'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Module'/><title type='text'>Dealing with Invalid Delegates with Exchange Web Services and Powershell</title><content type='html'>Invalid delegates have always been a tricky issue in Exchange an Invalid delegate happens when a mailbox that has a delegate setup and the delegate user account is deleted or disabled(has the Exchange attributes removed).  When your using the EWS delegate operations and a mailbox has an invalid delegate you get a message back to tell you the delegate doesn't map to an active directory user however it doesn't tell you who that user was and what type of delegate access that user had. You also can't use the EWS delegate operations to remove a user in this state so you end up with a kind of stalemate solution that requires a manual delete with Outlook. Before going any further its worth covering briefly what happens when you add a delegate to mailbox within Oultook there are three areas of the delegator's mailbox that gets modified.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Local freebusy object in the mailbox&lt;/li&gt;&lt;li&gt;Permissions on folders that are given access to&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Rules collection if forward meeting requests option selected&lt;/li&gt;&lt;/ul&gt;The last things that gets changed is the publicDelegates active directory property.&lt;br /&gt;&lt;br /&gt;What happens to the LocalFreeBusy object is of the most interest and has been documented in the &lt;a href="http://msdn.microsoft.com/en-us/library/cc425488%28v=exchg.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc425488%28v=exchg.80%29.aspx&lt;/a&gt; protocol document basically it comes down to the following 7 Mapi properties on the LocalFreeBusy object.&lt;br /&gt;&lt;br /&gt;PidTagScheduleInfoDelegatorWantsInfo&lt;br /&gt;PidTagScheduleInfoDelegatorWantsCopy&lt;br /&gt;&lt;br /&gt;PidTagScheduleInfoDelegateNamesW&lt;br /&gt;PidTagScheduleInfoDelegateEntryIds&lt;br /&gt;PidTagDelegateFlags&lt;br /&gt;&lt;br /&gt;These last three properties contain specific setting for each delegate user including the X500DN of the delegated users within PidTagScheduleInfoDelegateEntryIds (Its stored as Addessbook entryid).&lt;br /&gt;&lt;br /&gt;If your observant you would have only counted 5 properties which is all that are documented in the protocol document. If you look at the object with a Mapi editor however you would discover two more undocumented properties that also hold information about delegates.&lt;br /&gt;&lt;br /&gt;x6870 and x6871&lt;br /&gt;&lt;br /&gt;To get the localfreebusy object in a mailbox using EWS there are a few methods you can use the first is to search the NON_IPM_Subtree for and find the FreeBusy Data folder and then search that folder for an item with a subject of localfreebusy. The other option is to use is the PR_FREEBUSY_ENTRYIDS extended property on the Non_IPM_Subtree which contains an array of FreeBusy EntryID's which the 2nd element is the LocalFreeBusy Object which you can convert into a EWSid using a convertid operation and then bind directly to that item.&lt;br /&gt;&lt;br /&gt;So if your using EWS and you get "The delegate does not map to a user in the Active Directory" and you want to find out which user this refers to you can compare whats returned in PidTagScheduleInfoDelegateNamesW with the valid delegates you back with normal operation you should be able to work out the invalid delegate.&lt;br /&gt;&lt;br /&gt;To demonstrate this I've put some Powershell cmdlet's together so basically you can display firstly the Raw property values, show what is invalid doing the compare i talked about above and then lastly you can do a unsupported remove which basically will remove the invalid entries out of the extended properties. The reason i said this is unsupported because its not really tested and its also only modifies the raw properties so all the other things like mailbox permission, forward rules will still be in-place (although I've also created some cmdlets to clean up invalid forward rules as well that I'll talk about in a separate post).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Get-MessageOps.MailboxDelegatesRaw&lt;/span&gt; : This Cmdlet retrieves the delegates from a mailbox by reading the Raw Mapi properties from the Local Freebusy Item in a mailbox.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;eg Get-MessageOps.MailboxDelegates –p $ewsprofile –identity mailbox@domain.com&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Get-MessageOps.MailboxDelegatesInvalid&lt;/span&gt; :  This Cmdlet retrieves the delegates from a mailbox by reading the Raw Mapi properties from the Local Freebusy Item in a mailbox and then compares them against what is retrieved using a normal getdelegate operation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;eg. Get-MessageOps.MailboxDelegatesInvalid –p $ewsprofile –identity mailbox@domain.com&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Remove-MessageOps.MailboxDelegatesInvalid.Unsupported&lt;/span&gt; : This Cmdlet retrieves the delegates from a mailbox by reading the Raw Mapi properties from the Local Freebusy Item in a mailbox and then compares them against what is retrieved using a normal getdelegate operation. It then modifies the Raw Mapi properties on the local freebusy object and removes any entries that it finds are invalid. Note this doesn’t remove the delegate forwarding rules if it exists and also doesn’t remove any delegate permissions if they have been set.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;eg. Remove-MessageOps.MailboxDelegatesInvalid.Unsupported  –p $ewsprofile –identity mailbox@domain.com&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To use these cmdlets you need to download the following module &lt;a href="http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip"&gt;http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-7417445414545337718?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/7417445414545337718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=7417445414545337718' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7417445414545337718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7417445414545337718'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/03/dealing-with-invalid-delegates-with.html' title='Dealing with Invalid Delegates with Exchange Web Services and Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-5697709789844514975</id><published>2011-03-10T20:55:00.003+11:00</published><updated>2011-03-10T23:04:30.786+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Using the PR_Folder_Path property in Exchange Web Services to show the folder path</title><content type='html'>The PR_Folder_PathName Mapi property is a useful property to use when migrating an application that uses WebDAV to EWS where the webdav application has used the DAV:href property paths or if you just want to display the fullpath to a folder delimited by "\" which may useful for other applications.&lt;br /&gt;&lt;br /&gt;The PR_Folder_PathName property returns the fullpath to a folder that is delimited by the &lt;a href="http://en.wikipedia.org/wiki/Byte_order_mark"&gt;byte order mark&lt;/a&gt; FE-FF so if you want to return a \ delimited path you need to replace these values in the Unicode string that is returned when you retrieve this property.&lt;br /&gt;&lt;br /&gt;eg in the managed API&lt;br /&gt;&lt;span style="font-size:78%;"&gt;&lt;br /&gt;static void getPath(ExchangeService service) {&lt;br /&gt;          ExtendedPropertyDefinition PR_Folder_Path = new ExtendedPropertyDefinition(26293, MapiPropertyType.String);&lt;br /&gt;          PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_Folder_Path };&lt;br /&gt;          Folder foFolder = Folder.Bind(service, WellKnownFolderName.RecoverableItemsDeletions, psPropSet);&lt;br /&gt;          Object fpPath = null;&lt;br /&gt;          foFolder.TryGetProperty(PR_Folder_Path,out fpPath);&lt;br /&gt;          String fpPathString = Encoding.Unicode.GetString(HexStringToByteArray(BitConverter.ToString(UnicodeEncoding.Unicode.GetBytes((String)fpPath)).Replace("FE-FF", "5C-00").Replace("-", "")));&lt;br /&gt;          Console.WriteLine(fpPathString);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static Byte[] HexStringToByteArray(String HexString)&lt;br /&gt;        {&lt;br /&gt;            Byte[] ByteArray = new Byte[HexString.Length / 2];&lt;br /&gt;            for (int i = 0; i &amp;lt; HexString.Length; i += 2)&lt;br /&gt;            {&lt;br /&gt;                ByteArray[i / 2] = Convert.ToByte(HexString.Substring(i, 2), 16);&lt;br /&gt;            }&lt;br /&gt;            return ByteArray;&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-5697709789844514975?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/5697709789844514975/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=5697709789844514975' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/5697709789844514975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/5697709789844514975'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/03/using-prfolderpath-property-in-exchange.html' title='Using the PR_Folder_Path property in Exchange Web Services to show the folder path'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-5240335981521693534</id><published>2011-02-21T19:29:00.006+11:00</published><updated>2011-02-22T10:01:08.050+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010 SP1'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Module'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Exporting and Uploading Mailbox Items using Exchange Web Services using the new ExportItems and UploadItems operations in Exchange 2010 SP1</title><content type='html'>Two new EWS Operations &lt;a href="http://msdn.microsoft.com/en-us/library/ff709523%28v=exchg.140%29.aspx"&gt;ExportItems&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/ff709490%28v=exchg.140%29.aspx"&gt;UploadItems &lt;/a&gt;where introduced in Exchange 2010 SP1 that allowed you to do a number of useful things that where previously not possible using Exchange Web Services.  Any object that Exchange stores is basically a collection of properties for example a message object is a collection of Message properties, Recipient properties and Attachment properties with a few meta properties that describe the underlying storage thrown in. Normally when using EWS you can access these properties in a number of a ways eg one example is using the strongly type objects such as emailmessage that presents the underlying properties in an intuitive way that's easy to use. Another way is using Extended Properties to access the underlying properties directly.  However previously in EWS there was no method to access every property of a message hence there is no way to export or import an item and maintain full fidelity of every property on that item (you could export the item as an EML but this doesn't provide any fidelity of the properties on item).&lt;br /&gt;&lt;br /&gt;Now with these two new operations there is a method of exporting and uploading items and maintaining all the Mapi properties. The only real restriction is by default the  maximum import payload is 25MB of base64 encoded data but these setting can be modified in the web.config file.  The export/import format that these two operations use in the Fast Transfer Stream format which is a stream of all the Exchange properties separated with meta properties to represent the different property collections on the Item. This format while it bares some similarity to TNEF and Compound Message format (MSG) is not the same.  If your interested in learning more about the Fast Transfer Stream format there is a good presentation &lt;a href="http://channel9.msdn.com/posts/Exchange-Fast-Transfer"&gt;here&lt;/a&gt;. To help read the FastTransferStream files that are produced by the ExportItems offline I've created a roughly little parser and browser and posted this on &lt;a href="http://ewsftstream.codeplex.com/"&gt;codeplex&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;There are no methods in the EWS Managed API to use these operations so you need to use EWS Proxy code or just raw SOAP when writing applications or script to use this. However you do need the EWSid's of the Items and Folder to upload or export items and the Managed API is the easiest way of getting these. For this post I've create a sample of exporting the last received item in the Inbox first using the EWS Managed API to find the last item and then use raw SOAP to export the items.&lt;br /&gt;&lt;br /&gt;Before i go through that sample I've also added some cmdlets to the powershell module that i've been working on that use these operations that simplifies the code from powershell down to a couple of lines of code rather then the long script i'll post below. The new cmdlets i wrote are.&lt;br /&gt;&lt;br /&gt;Export-MessageOps.Item Exports an Item as a binary FTS Stream that can be stored in memory or written to a file&lt;br /&gt;&lt;br /&gt;eg&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;$item = Get-MessageOps.Messages -p $ewsprofile -fp \\Inbox -MessageCount 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Export-MessageOps.Item -ewsprofile $ewsprofile -ewsid $item.id -FileName c:\download\item.fts&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Export-MessageOps.Items Exports multiple Items as a binary FTS Stream that can be stored in memory or written to multiple files in a directory&lt;br /&gt;&lt;br /&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;o:officedocumentsettings&gt;   &lt;o:allowpng/&gt;  &lt;/o:OfficeDocumentSettings&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:trackmoves/&gt;   &lt;w:trackformatting/&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:donotpromoteqf/&gt;   &lt;w:lidthemeother&gt;EN-AU&lt;/w:LidThemeOther&gt;   &lt;w:lidthemeasian&gt;X-NONE&lt;/w:LidThemeAsian&gt;   &lt;w:lidthemecomplexscript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:splitpgbreakandparamark/&gt;    &lt;w:enableopentypekerning/&gt;    &lt;w:dontflipmirrorindents/&gt;    &lt;w:overridetablestylehps/&gt;   &lt;/w:Compatibility&gt;   &lt;m:mathpr&gt;    &lt;m:mathfont val="Cambria Math"&gt;    &lt;m:brkbin val="before"&gt;    &lt;m:brkbinsub val="&amp;#45;-"&gt;    &lt;m:smallfrac val="off"&gt;    &lt;m:dispdef/&gt;    &lt;m:lmargin val="0"&gt;    &lt;m:rmargin val="0"&gt;    &lt;m:defjc val="centerGroup"&gt;    &lt;m:wrapindent val="1440"&gt;    &lt;m:intlim val="subSup"&gt;    &lt;m:narylim val="undOvr"&gt;   &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" defunhidewhenused="true" defsemihidden="true" defqformat="false" defpriority="99" latentstylecount="267"&gt;   &lt;w:lsdexception locked="false" priority="0" semihidden="false" unhidewhenused="false" qformat="true" name="Normal"&gt;   &lt;w:lsdexception locked="false" priority="9" semihidden="false" unhidewhenused="false" qformat="true" name="heading 1"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 2"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 3"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 4"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 5"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 6"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 7"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 8"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 9"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 1"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 2"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 3"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 4"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 5"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 6"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 7"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 8"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 9"&gt;   &lt;w:lsdexception locked="false" priority="35" qformat="true" name="caption"&gt;   &lt;w:lsdexception locked="false" priority="10" semihidden="false" unhidewhenused="false" qformat="true" name="Title"&gt;   &lt;w:lsdexception locked="false" priority="1" name="Default Paragraph Font"&gt;   &lt;w:lsdexception locked="false" priority="11" semihidden="false" unhidewhenused="false" qformat="true" name="Subtitle"&gt;   &lt;w:lsdexception locked="false" priority="22" semihidden="false" unhidewhenused="false" qformat="true" name="Strong"&gt;   &lt;w:lsdexception locked="false" priority="20" semihidden="false" unhidewhenused="false" qformat="true" name="Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="59" semihidden="false" unhidewhenused="false" name="Table Grid"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Placeholder Text"&gt;   &lt;w:lsdexception locked="false" priority="1" semihidden="false" unhidewhenused="false" qformat="true" name="No Spacing"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Revision"&gt;   &lt;w:lsdexception locked="false" priority="34" semihidden="false" unhidewhenused="false" qformat="true" name="List Paragraph"&gt;   &lt;w:lsdexception locked="false" priority="29" semihidden="false" unhidewhenused="false" qformat="true" name="Quote"&gt;   &lt;w:lsdexception locked="false" priority="30" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Quote"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="19" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="21" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="31" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Reference"&gt;   &lt;w:lsdexception locked="false" priority="32" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Reference"&gt;   &lt;w:lsdexception locked="false" priority="33" semihidden="false" unhidewhenused="false" qformat="true" name="Book Title"&gt;   &lt;w:lsdexception locked="false" priority="37" name="Bibliography"&gt;   &lt;w:lsdexception locked="false" priority="39" qformat="true" name="TOC Heading"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable  {mso-style-name:"Table Normal";  mso-tstyle-rowband-size:0;  mso-tstyle-colband-size:0;  mso-style-noshow:yes;  mso-style-priority:99;  mso-style-parent:"";  mso-padding-alt:0cm 5.4pt 0cm 5.4pt;  mso-para-margin-top:0cm;  mso-para-margin-right:0cm;  mso-para-margin-bottom:10.0pt;  mso-para-margin-left:0cm;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:"Calibri","sans-serif";  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;  mso-fareast-language:EN-US;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-style: italic;"&gt;$items = Get-MessageOps.Messages -p $ewsprofile -fp \\inbox -MessageCount 20&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Export-MessageOps.Items -p $ewsprofile -DirectoryName c:\temp -Items $items&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;Import-MessageOps.Item Imports an Item that has been exported using the Export cmdlets the input can be either a ExportItemsResponseMessageType or a FileName of a file that is in FTS format.&lt;span style="color: rgb(43, 145, 175);font-family:Consolas;font-size:9.5pt;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;o:officedocumentsettings&gt;   &lt;o:allowpng/&gt;  &lt;/o:OfficeDocumentSettings&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:trackmoves/&gt;   &lt;w:trackformatting/&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:donotpromoteqf/&gt;   &lt;w:lidthemeother&gt;EN-AU&lt;/w:LidThemeOther&gt;   &lt;w:lidthemeasian&gt;X-NONE&lt;/w:LidThemeAsian&gt;   &lt;w:lidthemecomplexscript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:splitpgbreakandparamark/&gt;    &lt;w:enableopentypekerning/&gt;    &lt;w:dontflipmirrorindents/&gt;    &lt;w:overridetablestylehps/&gt;   &lt;/w:Compatibility&gt;   &lt;m:mathpr&gt;    &lt;m:mathfont val="Cambria Math"&gt;    &lt;m:brkbin val="before"&gt;    &lt;m:brkbinsub val="&amp;#45;-"&gt;    &lt;m:smallfrac val="off"&gt;    &lt;m:dispdef/&gt;    &lt;m:lmargin val="0"&gt;    &lt;m:rmargin val="0"&gt;    &lt;m:defjc val="centerGroup"&gt;    &lt;m:wrapindent val="1440"&gt;    &lt;m:intlim val="subSup"&gt;    &lt;m:narylim val="undOvr"&gt;   &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" defunhidewhenused="true" defsemihidden="true" defqformat="false" defpriority="99" latentstylecount="267"&gt;   &lt;w:lsdexception locked="false" priority="0" semihidden="false" unhidewhenused="false" qformat="true" name="Normal"&gt;   &lt;w:lsdexception locked="false" priority="9" semihidden="false" unhidewhenused="false" qformat="true" name="heading 1"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 2"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 3"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 4"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 5"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 6"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 7"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 8"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 9"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 1"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 2"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 3"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 4"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 5"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 6"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 7"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 8"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 9"&gt;   &lt;w:lsdexception locked="false" priority="35" qformat="true" name="caption"&gt;   &lt;w:lsdexception locked="false" priority="10" semihidden="false" unhidewhenused="false" qformat="true" name="Title"&gt;   &lt;w:lsdexception locked="false" priority="1" name="Default Paragraph Font"&gt;   &lt;w:lsdexception locked="false" priority="11" semihidden="false" unhidewhenused="false" qformat="true" name="Subtitle"&gt;   &lt;w:lsdexception locked="false" priority="22" semihidden="false" unhidewhenused="false" qformat="true" name="Strong"&gt;   &lt;w:lsdexception locked="false" priority="20" semihidden="false" unhidewhenused="false" qformat="true" name="Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="59" semihidden="false" unhidewhenused="false" name="Table Grid"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Placeholder Text"&gt;   &lt;w:lsdexception locked="false" priority="1" semihidden="false" unhidewhenused="false" qformat="true" name="No Spacing"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Revision"&gt;   &lt;w:lsdexception locked="false" priority="34" semihidden="false" unhidewhenused="false" qformat="true" name="List Paragraph"&gt;   &lt;w:lsdexception locked="false" priority="29" semihidden="false" unhidewhenused="false" qformat="true" name="Quote"&gt;   &lt;w:lsdexception locked="false" priority="30" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Quote"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="19" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="21" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="31" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Reference"&gt;   &lt;w:lsdexception locked="false" priority="32" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Reference"&gt;   &lt;w:lsdexception locked="false" priority="33" semihidden="false" unhidewhenused="false" qformat="true" name="Book Title"&gt;   &lt;w:lsdexception locked="false" priority="37" name="Bibliography"&gt;   &lt;w:lsdexception locked="false" priority="39" qformat="true" name="TOC Heading"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable  {mso-style-name:"Table Normal";  mso-tstyle-rowband-size:0;  mso-tstyle-colband-size:0;  mso-style-noshow:yes;  mso-style-priority:99;  mso-style-parent:"";  mso-padding-alt:0cm 5.4pt 0cm 5.4pt;  mso-para-margin-top:0cm;  mso-para-margin-right:0cm;  mso-para-margin-bottom:10.0pt;  mso-para-margin-left:0cm;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:"Calibri","sans-serif";  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;  mso-fareast-language:EN-US;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;p style="font-style: italic;" class="MsoNormal"&gt;Import-MessageOps.Item -p $ewsprofile -fp \\inbox -Filename c:\item.fts&lt;/p&gt;Import-MessageOps.Items Import multiple Items exported using the Export-MessageOps.Items cmdlet&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;$exItems = Export-MessageOps.Items -p $ewsprofile -Items $items&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Import-MessageOps.Items -p $ewsprofile -fp \\inbox -Items $exItems &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To use these cmdlets you need the following module &lt;a href="http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip"&gt;http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I posted a downloadable copy of the following EWS Managed API script &lt;a href="http://msgdev.mvps.org/exdevblog/expitm.zip"&gt;here &lt;/a&gt;the code itself looks like&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;$MailboxName = "mailbox@domain.com"&lt;br /&gt;$fileName = 'c:\exp.fts'&lt;br /&gt;$cred = New-Object System.Net.NetworkCredential("username@domain.com","password")&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)&lt;br /&gt;$service.TraceEnabled = $false&lt;br /&gt;&lt;br /&gt;$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()&lt;br /&gt;$sidbind = "LDAP://&amp;lt;SID=" + $windowsIdentity.user.Value.ToString() + "&amp;gt;"&lt;br /&gt;$aceuser = [ADSI]$sidbind&lt;br /&gt;$service.Credentials = $cred&lt;br /&gt;$service.autodiscoverurl($MailboxName,{$true})&lt;br /&gt;&lt;br /&gt;$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)&lt;br /&gt;&lt;br /&gt;$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView(1)&lt;br /&gt;$findResults = $service.FindItems($folderid,$view)&lt;br /&gt;$itemid = $findResults.Items[0].Id.Uniqueid&lt;br /&gt;&lt;br /&gt;$expRequest = @"&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;&lt;br /&gt;&amp;lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br /&gt;      xmlns:xsd="http://www.w3.org/2001/XMLSchema"&lt;br /&gt;      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&lt;br /&gt;      xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"&lt;br /&gt;      xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"&amp;gt;&lt;br /&gt;  &amp;lt;soap:Header&amp;gt;&lt;br /&gt;    &amp;lt;t:RequestServerVersion Version="Exchange2010_SP1" /&amp;gt;&lt;br /&gt;  &amp;lt;/soap:Header&amp;gt;&lt;br /&gt;  &amp;lt;soap:Body&amp;gt;&lt;br /&gt;    &amp;lt;m:ExportItems&amp;gt;&lt;br /&gt;      &amp;lt;m:ItemIds&amp;gt;&lt;br /&gt;        &amp;lt;t:ItemId Id="$itemId"/&amp;gt;&lt;br /&gt;      &amp;lt;/m:ItemIds&amp;gt;&lt;br /&gt;    &amp;lt;/m:ExportItems&amp;gt;&lt;br /&gt;  &amp;lt;/soap:Body&amp;gt;&lt;br /&gt;&amp;lt;/soap:Envelope&amp;gt;&lt;br /&gt;"@&lt;br /&gt;$mbMailboxFolderURI = New-Object System.Uri($service.url)&lt;br /&gt;$wrWebRequest = [System.Net.WebRequest]::Create($mbMailboxFolderURI)&lt;br /&gt;$wrWebRequest.KeepAlive = $false;&lt;br /&gt;$wrWebRequest.Headers.Set("Pragma", "no-cache");&lt;br /&gt;$wrWebRequest.Headers.Set("Translate", "f");&lt;br /&gt;$wrWebRequest.Headers.Set("Depth", "0");&lt;br /&gt;$wrWebRequest.ContentType = "text/xml";&lt;br /&gt;$wrWebRequest.ContentLength = $expRequest.Length;&lt;br /&gt;$wrWebRequest.Timeout = 60000;&lt;br /&gt;$wrWebRequest.Method = "POST";&lt;br /&gt;$wrWebRequest.Credentials = $cred&lt;br /&gt;$bqByteQuery = [System.Text.Encoding]::ASCII.GetBytes($expRequest);&lt;br /&gt;$wrWebRequest.ContentLength = $bqByteQuery.Length;&lt;br /&gt;$rsRequestStream = $wrWebRequest.GetRequestStream();&lt;br /&gt;$rsRequestStream.Write($bqByteQuery, 0, $bqByteQuery.Length);&lt;br /&gt;$rsRequestStream.Close();&lt;br /&gt;$wrWebResponse = $wrWebRequest.GetResponse();&lt;br /&gt;$rsResponseStream = $wrWebResponse.GetResponseStream()&lt;br /&gt;$sr = new-object System.IO.StreamReader($rsResponseStream);&lt;br /&gt;$rdResponseDocument = New-Object System.Xml.XmlDocument&lt;br /&gt;$rdResponseDocument.LoadXml($sr.ReadToEnd());&lt;br /&gt;$Datanodes = @($rdResponseDocument.getElementsByTagName("m:Data"))&lt;br /&gt;if ($Datanodes.length -ne 0){&lt;br /&gt;    $Data = [System.Convert]::FromBase64String($Datanodes[0].'#text')&lt;br /&gt;    $fsFileStream = new-object system.io.filestream $fileName, ([io.filemode]::create), ([io.fileaccess]::write), ([io.fileshare]::none)&lt;br /&gt;    $fsFileStream.Write($Data, 0, $Data.Length);&lt;br /&gt;    $fsFileStream.Close();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-5240335981521693534?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/5240335981521693534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=5240335981521693534' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/5240335981521693534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/5240335981521693534'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/02/exporting-and-uploading-mailbox-items.html' title='Exporting and Uploading Mailbox Items using Exchange Web Services using the new ExportItems and UploadItems operations in Exchange 2010 SP1'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-7735666928775396515</id><published>2011-02-08T15:17:00.003+11:00</published><updated>2011-02-08T16:24:31.444+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010 SP1'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Module'/><title type='text'>Creating Inbox Rules with the EWS Managed API in Exchange 2010 SP1 with Powershell</title><content type='html'>One of the new features that was added in Exchange Web Services in 2010 SP1 (and improved in the Exchange Management Shell) was the ability to add Inbox Rules. Previously the only method for doing this programatically was a variety of Mapi methods some of which where not particular easy to use. Using the Exchange Management Shell New-InboxRule, Get-InboxRule and Set-InboxRule cmdlets offers an easy one-liner approach for the Admin but if you want to run your code as a non admin or you want to take advantage of EWS Impersonation to create rules on behalf of the user then Exchange Web Services is a good option for this.&lt;br /&gt;&lt;br /&gt;There are 3 major components to rules&lt;br /&gt;&lt;ul&gt;&lt;li&gt; RuleConditions&lt;/li&gt;&lt;li&gt; RuleExceptions (Optional)&lt;/li&gt;&lt;li&gt; RuleActions&lt;/li&gt;&lt;/ul&gt;Rule Conditions and Exceptions are essential the same they use the same objecttype RulePredicates the difference is that the conditions in ruleconidtions dictate what items a rule fires on and the exceptions dictates the conditions it doesn't fire on.&lt;br /&gt;&lt;br /&gt;With both the RulePredicates and RuleActions to cater for actions such as moving items, replying with an auto response etc you will need to use other EWS operations to find the EWSID's of the particular folder or autoreply message you want to work with so this will require the use of other code. Also for conditions if you have used an email address the address's stored in rule objects are in EX type so using the EWS Resolve names operations can be useful to resolve the name back to an SMTP Address or users displayName.&lt;br /&gt;&lt;br /&gt;The following example shows how to create a Move rule based on the Subject of a message it uses a function to find the EWS folderid of the folder to move the message to. Note this script could be easily adapted to instead of using the Subject to move the message move the message based on a X-header eg by modifying the following line&lt;br /&gt;&lt;br /&gt;$nrNewRule.Conditions.ContainsHeaderStrings.Add("X-SpamScore: 7");&lt;br /&gt;&lt;br /&gt;would add a condition to move a message based on a message header.&lt;br /&gt;&lt;br /&gt;For those following along with the module code I've been writing I've written some rule cmdlets to go along with this. I haven't tried to Jam everything to be a one-liner like the EMS cmdlets but the advantage of the module is that you can make use of the other cmldets for getting folders, address etc without the need for other large functions for example the same script to create a rule using the module is&lt;br /&gt;&lt;br /&gt;New-MessageOps.MailboxFolder -p $ewsprofile –id User@domain.com -fp "\\" -FolderName "SPAMFolder"&lt;br /&gt;$nrNewRule = New-Object Microsoft.Exchange.WebServices.Data.Rule&lt;br /&gt;$nrNewRule.DisplayName = "SPAMfolderRule";&lt;br /&gt;$nrNewRule.Conditions.ContainsSubjectStrings.Add("Sales Reports");&lt;br /&gt;$nrNewRule.Actions.MoveToFolder = (get-messageops.mailboxfolder -p $ewsprofile –id User@domain.com -FolderPath "\\SPAMFolder").Id&lt;br /&gt;New-MessageOps.InboxRule -p $ewsprofile –id User@domain.com -Rule $nrNewRule&lt;br /&gt;&lt;br /&gt;The other thing I've done with the Module is create a cmdlet that flattens out the Rule conditions and Actions into something that an admin can read. The is useful in reporting as its can be hard to spot using the native objects to use this for example&lt;br /&gt;&lt;br /&gt;Get-MessageOps.InboxRuleReport -p $ewsprofile&lt;span style=""&gt;  &lt;/span&gt;| export-csv -notype c:\InboxRules.csv &lt;p&gt;&lt;/p&gt;  Will produce a human readable export of the rules and condition into a CSV file. To use any of these module cmdlets you need the following download &lt;a href="http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip"&gt;http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For the straight EWS Managed API powershell version I've put a download of this script &lt;a href="http://msgdev.mvps.org/exdevblog/cewsrule.zip"&gt;here &lt;/a&gt;the code itself looks like&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;$mailbox = "user@domain.com"&lt;br /&gt;$fldname = "\\Inbox\Sales"&lt;br /&gt;&lt;br /&gt;Function FindTargetFolder($FolderPath){&lt;br /&gt; $tfTargetFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$mailbox)&lt;br /&gt; $pfArray = $FolderPath.Split("\")&lt;br /&gt; for ($lint = 2; $lint -lt $pfArray.Length; $lint++) {&lt;br /&gt;     $pfArray[$lint]&lt;br /&gt;     $fvFolderView = new-object Microsoft.Exchange.WebServices.Data.FolderView(1)&lt;br /&gt;     $SfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$pfArray[$lint])&lt;br /&gt;             $findFolderResults = $service.FindFolders($tfTargetFolder.Id,$SfSearchFilter,$fvFolderView)&lt;br /&gt;     if ($findFolderResults.TotalCount -gt 0){&lt;br /&gt;         foreach($folder in $findFolderResults.Folders){&lt;br /&gt;             $tfTargetFolder = $folder            &lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;     else{&lt;br /&gt;         "Error Folder Not Found"&lt;br /&gt;         $tfTargetFolder = $null&lt;br /&gt;         break&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt; $Global:findFolder = $tfTargetFolder&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)&lt;br /&gt;$service.TraceEnabled = $false&lt;br /&gt;&lt;br /&gt;$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()&lt;br /&gt;$sidbind = "LDAP://&amp;lt;SID=" + $windowsIdentity.user.Value.ToString() + "&amp;gt;"&lt;br /&gt;$aceuser = [ADSI]$sidbind&lt;br /&gt;$service.autodiscoverurl($mailbox,{$true})&lt;br /&gt;&lt;br /&gt;$irInboxRules = service.GetInboxRules&lt;br /&gt;&lt;br /&gt;$nrNewRule = New-Object Microsoft.Exchange.WebServices.Data.Rule&lt;br /&gt;$nrNewRule.DisplayName = "Move all Mails with Sales Reports in Subject"&lt;br /&gt;$nrNewRule.Conditions.ContainsSubjectStrings.Add("Sales Reports");&lt;br /&gt;&lt;br /&gt;FindTargetFolder($fldname)&lt;br /&gt;&lt;br /&gt;$nrNewRule.Actions.MoveToFolder = $Global:findFolder.Id.UniqueId&lt;br /&gt;&lt;br /&gt;$RuleOperation = New-Object Microsoft.Exchange.WebServices.Data.createRuleOperation[] 1&lt;br /&gt;$RuleOperation[0] = $nrNewRule&lt;br /&gt;&lt;br /&gt;$service.UpdateInboxRules($RuleOperation,$irInboxRules.OutlookRuleBlobExists)&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-7735666928775396515?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/7735666928775396515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=7735666928775396515' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7735666928775396515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7735666928775396515'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/02/creating-inbox-rules-with-ews-managed.html' title='Creating Inbox Rules with the EWS Managed API in Exchange 2010 SP1 with Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-7724107569710349090</id><published>2011-01-31T19:44:00.007+11:00</published><updated>2011-02-15T16:57:30.287+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010 SP1'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Dealing with Throttling restrictions in Exchange Web Services on Exchange 2010 SP1 in scripts and code</title><content type='html'>In Exchange 2010 SP1 throttling is enabled by default and while for the best part this is a good thing there are a few things you may need to be careful of if you have written code that retrieves a large number of items from a mailbox folder.&lt;br /&gt;&lt;br /&gt;While you can disable or set custom throttling polices for your application or scripts its generally a better idea to build your code to work within these throttling thresholds.  With EWS the throttling policies affect a number of different areas from the number of concurrent connections one user can establish to a server, limits on the number of subscriptions and also the CPU time one particular user can consume when executing particular operations. For the most part if your using simple single threaded scripts where your not executing requests concurrently most of the settings wont have any bearing. The one policy setting that will have a direct affect on existing scripts or code is the EWSFindCountLimit which by default is limited to 1000.  This is discussed in a little more detail here &lt;a href="https://blogs.msdn.com/b/exchangedev/archive/2010/03/12/throttling-policies-and-the-ewsfindcountlimit.aspx"&gt;https://blogs.msdn.com/b/exchangedev/archive/2010/03/12/throttling-policies-and-the-ewsfindcountlimit.aspx.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The upshot of this is if you have code where you have set a page size greater than 1000 and your not checking IncludesLastItemInRange to ensure you have retrieved all the items within the scope of your findItems or findfolder request then your current code may will only retrieve the first 1000 items in a folder .To cater for this if your using Powershell and the EWS Managed API you need to use something like a Do{}(Where) to write code loop to ensure you make followup finditem/findfolder requests to retrieve all the items from a particular folder. For example to loop through all the messages within an inbox using a pagesize of 1000 would look like&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt; $folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)&lt;br /&gt; $ivItemView =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)&lt;br /&gt; $fiResult = ""&lt;br /&gt; do{&lt;br /&gt;     $fiResult = $Service.FindItems($folderid,$ivItemView)&lt;br /&gt;     foreach($Items in $fiResult.Items){&lt;br /&gt;         $Items.Subject&lt;br /&gt;     }&lt;br /&gt;     $ivItemView.offset += $fiResult.Items.Count&lt;br /&gt; }while($fiResult.MoreAvailable -eq $true)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The other setting to be careful of is the EWSFastSearchTimeoutInSeconds which is set to 60 seconds by default. If your querying folders with a large number of items with complex filters then this could be a problem. Fortunately the Entry point EWS offers to make Exchange Search queries should help counter problems with this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-7724107569710349090?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/7724107569710349090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=7724107569710349090' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7724107569710349090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/7724107569710349090'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/01/dealing-with-throttling-restrictions-in.html' title='Dealing with Throttling restrictions in Exchange Web Services on Exchange 2010 SP1 in scripts and code'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-6953860978311666805</id><published>2011-01-24T17:13:00.004+11:00</published><updated>2011-01-24T20:37:02.769+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='permissions'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='calendar'/><category scheme='http://www.blogger.com/atom/ns#' term='EMS'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Default Calendar permission Powershell GUI for Exchange 2010 SP1 and up</title><content type='html'>One of the new cmdlets in Exchange 2010 SP1 is the Set-MailboxFolderPermission cmdlet which was an addition to the other Exchange 2010 RTM folder permission cmdlets get-MailboxFolderPermission and add-MailboxFolderPermission. What this cmdlet gives you the ability to do is update the permissions of any folder within a mailbox as long as you are a member of the RBAC roles that allows you set them as specified in &lt;a href="http://technet.microsoft.com/en-us/library/dd638132.aspx"&gt;http://technet.microsoft.com/en-us/library/dd638132.aspx&lt;/a&gt;. Another thing this cmdlet does is give me the ability to revisit the default calendar folder permission GUI from this &lt;a href="http://gsexdev.blogspot.com/2008/03/default-calendar-permission-powershell.html"&gt;post&lt;/a&gt;(which used EWS and will still work okay on 2010) and rewrite this to be able to be used in Remote powershell so it will work against any 2010 SP1 server as well as anything else that supports these cmdlets such as live@edu or Office365.&lt;br /&gt;&lt;br /&gt;  If you don't really want a GUI and would rather just export the permissions to CSV modify them and then reimport them that's easy to do for example to export the settings to a csv file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;$rptCollection = @()&lt;br /&gt;$mailboxes = get-mailbox -ResultSize Unlimited&lt;br /&gt;$mailboxes | foreach-object{&lt;br /&gt;    $alias = $_.alias + ":\Calendar"&lt;br /&gt;    $displayName = $_.DisplayName&lt;br /&gt;    write-host $alias&lt;br /&gt;     $permissions = Get-MailboxFolderPermission $alias | Where-Object {$_.Identity.ToString() -eq "Default"}&lt;br /&gt;    if($permissions -ne $null){&lt;br /&gt;        $stringPerms = ""&lt;br /&gt;        foreach($perms in $permissions.AccessRights){$stringPerms = $stringPerms + $perms + " "}&lt;br /&gt;        Add-Member -InputObject $permissions -MemberType NoteProperty -Name "Alias" -Value $alias -Force&lt;br /&gt;        Add-Member -InputObject $permissions -MemberType NoteProperty -Name "StringAccessRights" -Value $stringPerms -Force&lt;br /&gt;            $rptCollection += $permissions&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;$rptCollection | export-csv -notypeInformation c:\defaultperms.csv&lt;br /&gt;&lt;br /&gt;To then re-import them from a csv file you can use&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;import-csv c:\defaultperms.csv | foreach-object{&lt;br /&gt;    "Seting Rights on " + $_.alias&lt;br /&gt;     Set-MailboxFolderPermission -id $_.alias -User $_.Identity -AccessRights $_.StringAccessRights&lt;br /&gt;    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Personally i like the GUI which is a little more snappier with the GUI I left the permission descriptions in Outlook format rather then switching them to the  accessrights role format(the great thing about standards is there are so many to choose from).  To run this GUI you need to first start a Remote powershell session and import the Exchange 2010 cmdlets or run it directly from within the EMS.  I've put a download of the new script &lt;a href="http://msgdev.mvps.org/exdevblog/caldefuserv2.zip"&gt;here &lt;/a&gt;the code looks like&lt;br /&gt;&lt;br /&gt;[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")&lt;br /&gt;[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;function GetPerms(){&lt;br /&gt;$logTable.clear()&lt;br /&gt;&lt;br /&gt;If ($seAuthCheck.Checked -eq $true){&lt;br /&gt;    $mailboxes = get-mailbox -server $snServerNameTextBox.Text -ResultSize Unlimited&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;    $mailboxes = get-mailbox -ResultSize Unlimited&lt;br /&gt;}&lt;br /&gt;$mailboxes | foreach-object{&lt;br /&gt;    $alias = $_.alias + ":\Calendar"&lt;br /&gt;    $displayName = $_.DisplayName&lt;br /&gt;    write-host $alias&lt;br /&gt;     $permissions = Get-MailboxFolderPermission $alias | Where-Object {$_.Identity.ToString() -eq "Default"}&lt;br /&gt;    if($permissions -ne $null){&lt;br /&gt;        Add-Member -InputObject $permissions -MemberType NoteProperty -Name "Alias" -Value $alias -Force&lt;br /&gt;        $stringPerms = ""&lt;br /&gt;        foreach($perms in $permissions.AccessRights){$stringPerms = $stringPerms + $perms + " "}&lt;br /&gt;        $logTable.rows.add($displayName,$permissions.alias,$stringPerms)&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;}&lt;br /&gt;$dgDataGrid.DataSource = $logTable&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Function UpdatePerms{&lt;br /&gt;if ($dgDataGrid.SelectedRows.Count -eq 0){&lt;br /&gt;    $mbtoSet =  $dgDataGrid.Rows[$dgDataGrid.CurrentCell.RowIndex].Cells[1].Value&lt;br /&gt;    $newperm = ""&lt;br /&gt;    switch ($npNewpermDrop.Text){&lt;br /&gt;        "None" {$newperm = "None"}&lt;br /&gt;        "FreeBusyTimeOnly" {$newperm = "AvailabilityOnly"}                                   &lt;br /&gt;        "FreeBusyTimeAndSubjectAndLocation" {$newperm = "LimitedDetails"}   &lt;br /&gt;        "Reviewer" {$newperm = "Reviewer"}   &lt;br /&gt;        "Contributer" {$newperm = "Contributer"}   &lt;br /&gt;        "Author" {$newperm = "Author"}   &lt;br /&gt;        "NonEditingAuthor" {$newperm = "NonEditingAuthor"}   &lt;br /&gt;        "PublishingAuthor"{$newperm = "PublishingAuthor"}   &lt;br /&gt;        "Author" {$newperm = "Author"}   &lt;br /&gt;        "Editor" {$newperm = "Editor"}   &lt;br /&gt;        "PublishingEditor"{$newperm = "PublishingEditor"}   &lt;br /&gt;    }&lt;br /&gt;    Set-MailboxFolderPermission -id $mbtoSet -User Default -AccessRights $newperm&lt;br /&gt;    write-host "Permission updated" + $npNewpermDrop.Text&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;    $lcLoopCount = 0&lt;br /&gt;    while ($lcLoopCount -le ($dgDataGrid.SelectedRows.Count-1)) {&lt;br /&gt;        $mbtoSet =  $dgDataGrid.SelectedRows[$lcLoopCount].Cells[1].Value&lt;br /&gt;       &lt;br /&gt;        switch ($npNewpermDrop.Text){&lt;br /&gt;            "None" {$newperm = "None"}&lt;br /&gt;            "FreeBusyTimeOnly" {$newperm = "AvailabilityOnly"}                                   &lt;br /&gt;            "FreeBusyTimeAndSubjectAndLocation" {$newperm = "LimitedDetails"}   &lt;br /&gt;            "Reviewer" {$newperm = "Reviewer"}   &lt;br /&gt;            "Contributer" {$newperm = "Contributer"}   &lt;br /&gt;            "Author" {$newperm = "Author"}   &lt;br /&gt;            "NonEditingAuthor" {$newperm = "NonEditingAuthor"}   &lt;br /&gt;            "PublishingAuthor"{$newperm = "PublishingAuthor"}   &lt;br /&gt;            "Author" {$newperm = "Author"}   &lt;br /&gt;            "Editor" {$newperm = "Editor"}   &lt;br /&gt;            "PublishingEditor"{$newperm = "PublishingEditor"}   &lt;br /&gt;        }&lt;br /&gt;        Set-MailboxFolderPermission -id $mbtoSet -User Default -AccessRights $newperm&lt;br /&gt;        write-host "Permission updated" + $npNewpermDrop.Text&lt;br /&gt;        $lcLoopCount += 1   &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;write-host "end PermUpdate"&lt;br /&gt;write-host "Refresh Perms"&lt;br /&gt;GetPerms&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$form = new-object System.Windows.Forms.form&lt;br /&gt;$form.Text = "Calender Permission Enum Tool"&lt;br /&gt;$Dataset = New-Object System.Data.DataSet&lt;br /&gt;$logTable = New-Object System.Data.DataTable&lt;br /&gt;$logTable.TableName = "ActiveSyncLogs"&lt;br /&gt;$logTable.Columns.Add("DisplayName");&lt;br /&gt;$logTable.Columns.Add("MailboxFolderId");&lt;br /&gt;$logTable.Columns.Add("Default-Permissions");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# Add Server DropLable&lt;br /&gt;$snServerNamelableBox = new-object System.Windows.Forms.Label&lt;br /&gt;$snServerNamelableBox.Location = new-object System.Drawing.Size(10,60)&lt;br /&gt;$snServerNamelableBox.size = new-object System.Drawing.Size(70,20)&lt;br /&gt;$snServerNamelableBox.Text = "ServerName"&lt;br /&gt;$form.Controls.Add($snServerNamelableBox)&lt;br /&gt;&lt;br /&gt;# Add ServerNameText&lt;br /&gt;$snServerNameTextBox = new-object System.Windows.Forms.TextBox&lt;br /&gt;$snServerNameTextBox.Location = new-object System.Drawing.Size(90,60)&lt;br /&gt;$snServerNameTextBox.size = new-object System.Drawing.Size(150,20)&lt;br /&gt;$snServerNameTextBox.Enabled = $false&lt;br /&gt;$form.Controls.Add($snServerNameTextBox)&lt;br /&gt;&lt;br /&gt;$seAuthCheck =  new-object System.Windows.Forms.CheckBox&lt;br /&gt;$seAuthCheck.Location = new-object System.Drawing.Size(250,60)&lt;br /&gt;$seAuthCheck.Size = new-object System.Drawing.Size(130,25)&lt;br /&gt;$seAuthCheck.Text = "Filter by"&lt;br /&gt;$seAuthCheck.Add_Click({if ($seAuthCheck.Checked -eq $true){&lt;br /&gt;            $snServerNameTextBox.Enabled = $true&lt;br /&gt;            }&lt;br /&gt;            else{&lt;br /&gt;            $snServerNameTextBox.Enabled = $false}})&lt;br /&gt;$form.Controls.Add($seAuthCheck)&lt;br /&gt;&lt;br /&gt;# Add Get Perms Button&lt;br /&gt;&lt;br /&gt;$gpgetperms = new-object System.Windows.Forms.Button&lt;br /&gt;$gpgetperms.Location = new-object System.Drawing.Size(10,20)&lt;br /&gt;$gpgetperms.Size = new-object System.Drawing.Size(140,23)&lt;br /&gt;$gpgetperms.Text = "Enumerate Permissions"&lt;br /&gt;$gpgetperms.Add_Click({GetPerms})&lt;br /&gt;$form.Controls.Add($gpgetperms)&lt;br /&gt;&lt;br /&gt;# Add New Permission Drop Down&lt;br /&gt;$npNewpermDrop = new-object System.Windows.Forms.ComboBox&lt;br /&gt;$npNewpermDrop.Location = new-object System.Drawing.Size(350,20)&lt;br /&gt;$npNewpermDrop.Size = new-object System.Drawing.Size(190,30)&lt;br /&gt;$npNewpermDrop.Items.Add("None")&lt;br /&gt;$npNewpermDrop.Items.Add("FreeBusyTimeOnly")&lt;br /&gt;$npNewpermDrop.Items.Add("FreeBusyTimeAndSubjectAndLocation")&lt;br /&gt;$npNewpermDrop.Items.Add("Reviewer")&lt;br /&gt;$npNewpermDrop.Items.Add("Contributer")&lt;br /&gt;$npNewpermDrop.Items.Add("Author")&lt;br /&gt;$npNewpermDrop.Items.Add("NonEditingAuthor")&lt;br /&gt;$npNewpermDrop.Items.Add("PublishingAuthor")&lt;br /&gt;$npNewpermDrop.Items.Add("Editor")&lt;br /&gt;$npNewpermDrop.Items.Add("PublishingEditor")&lt;br /&gt;$form.Controls.Add($npNewpermDrop)&lt;br /&gt;&lt;br /&gt;# Add Apply Button&lt;br /&gt;&lt;br /&gt;$exButton = new-object System.Windows.Forms.Button&lt;br /&gt;$exButton.Location = new-object System.Drawing.Size(550,20)&lt;br /&gt;$exButton.Size = new-object System.Drawing.Size(60,20)&lt;br /&gt;$exButton.Text = "Apply"&lt;br /&gt;$exButton.Add_Click({UpdatePerms})&lt;br /&gt;$form.Controls.Add($exButton)&lt;br /&gt;&lt;br /&gt;# New setting Group Box&lt;br /&gt;&lt;br /&gt;$OfGbox =  new-object System.Windows.Forms.GroupBox&lt;br /&gt;$OfGbox.Location = new-object System.Drawing.Size(320,0)&lt;br /&gt;$OfGbox.Size = new-object System.Drawing.Size(300,50)&lt;br /&gt;$OfGbox.Text = "New Permission Settings"&lt;br /&gt;$form.Controls.Add($OfGbox)&lt;br /&gt;&lt;br /&gt;# Add DataGrid View&lt;br /&gt;&lt;br /&gt;$dgDataGrid = new-object System.windows.forms.DataGridView&lt;br /&gt;$dgDataGrid.Location = new-object System.Drawing.Size(10,130)&lt;br /&gt;$dgDataGrid.size = new-object System.Drawing.Size(750,550)&lt;br /&gt;$dgDataGrid.AutoSizeColumnsMode = "AllCells"&lt;br /&gt;$dgDataGrid.SelectionMode = "FullRowSelect"&lt;br /&gt;$form.Controls.Add($dgDataGrid)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$form.Text = "Exchange 2010 Default Calendar Permissions Form"&lt;br /&gt;$form.size = new-object System.Drawing.Size(800,730)&lt;br /&gt;&lt;br /&gt;$form.autoscroll = $true&lt;br /&gt;$form.topmost = $true&lt;br /&gt;$form.Add_Shown({$form.Activate()})&lt;br /&gt;$form.ShowDialog()&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-6953860978311666805?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/6953860978311666805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=6953860978311666805' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6953860978311666805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6953860978311666805'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/01/default-calendar-permission-powershell.html' title='Default Calendar permission Powershell GUI for Exchange 2010 SP1 and up'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-6539732590360746610</id><published>2011-01-17T21:16:00.004+11:00</published><updated>2011-01-18T10:55:17.533+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Module'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Mailbox Size'/><title type='text'>Calculating Mailbox Sizes using Exchange Web Services and Powershell</title><content type='html'>Normally if you want to work out the size of a mailbox or the size of a  mailbox folder as an administrator you would use get-mailboxstatistics  and get-mailboxfolderstatistics the Exchange Management Shelll cmdlets  which are the fastest and easiest way of retrieving this information on  2007 and 2010. However if you want to get the Mailbox size using normal  user rights or the EMS cmdlets aren't an option then EWS can be used.  There is no one property inside a mailbox that can be used  to get  the total size of a mailbox so like you needed to do in 2003 and earlier  to calculate the size of a mailbox you need to get the size of each  mailbox folder then sum these together. To get the Size of the Mailbox  Folder and Deleted Items within a folder requires the use of the following extended Mapi properties&lt;br /&gt;&lt;br /&gt;PR_MESSAGE_SIZE_EXTENDED and PR_DELETED_MESSAGE_SIZE_EXTENDED&lt;br /&gt;&lt;br /&gt;To get the  properties on all of the folders in a Mailbox a Deep Traversal  findfolders operations from the Root of the Mailbox can be used.&lt;br /&gt;&lt;br /&gt;One of useful things you can do with EWS that you can't do in EMS with  the cmdlets is filter this query by the Mapi FolderClass (which is  different from the folderscope property). In the large script posted below I've  commented out the filter to do this but the lines are&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;##$folderItemType = "IPF.Note"&lt;br /&gt;##$sfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::FolderClass, $folderItemType)&lt;br /&gt;##$fiResult = $Service.FindFolders($folderidcnt,$sfSearchFilter,$fvFolderView)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A small example using the EWS Module I've been working on condenses this down to&lt;br /&gt;&lt;br /&gt;$ewsProfile = New-MessageOps.EWSProfile -id glen@domain.com&lt;br /&gt;Get-MessageOps.MailboxSize -p $ewsprofile&lt;br /&gt;&lt;br /&gt;To filter the result by foldertype you can use&lt;br /&gt;&lt;br /&gt;Get-MessageOps.MailboxSize -p $ewsprofile -FolderItemType "IPF.Contact"&lt;br /&gt;&lt;br /&gt;To use this you need download the module from &lt;a href="http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip"&gt;http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The normal EWS Managed API power shell script I've put a download of &lt;a href="http://msgdev.mvps.org/exdevblog/mbsizevm.zip"&gt;here &lt;/a&gt;the code looks like&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;$MailboxName = "user@domain.com"&lt;br /&gt;##$folderItemType = "IPF.Note"&lt;br /&gt;$rptCollection = @()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()&lt;br /&gt;$sidbind = "LDAP://&amp;lt;SID=" + $windowsIdentity.user.Value.ToString() + "&amp;gt;"&lt;br /&gt;$aceuser = [ADSI]$sidbind&lt;br /&gt;$service.AutodiscoverUrl($aceuser.mail.ToString(),{$true})&lt;br /&gt;&lt;br /&gt;$TotalItemCount = 0&lt;br /&gt;$TotalItemSize = 0&lt;br /&gt;&lt;br /&gt;"Checking : " + $MailboxName&lt;br /&gt;$folderidcnt = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)&lt;br /&gt;$fvFolderView =  New-Object Microsoft.Exchange.WebServices.Data.FolderView(10000)&lt;br /&gt;$fvFolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep;&lt;br /&gt;$psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)&lt;br /&gt;$PR_MESSAGE_SIZE_EXTENDED = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3592,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Long);&lt;br /&gt;$PR_DELETED_MESSAGE_SIZE_EXTENDED = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26267,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Long);&lt;br /&gt;$PR_DELETED_MSG_COUNT = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26176,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);&lt;br /&gt;$psPropertySet.Add($PR_MESSAGE_SIZE_EXTENDED);&lt;br /&gt;$psPropertySet.Add($PR_DELETED_MESSAGE_SIZE_EXTENDED);&lt;br /&gt;$psPropertySet.Add($PR_DELETED_MSG_COUNT);&lt;br /&gt;$fvFolderView.PropertySet = $psPropertySet;&lt;br /&gt;##$sfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::FolderClass, $folderItemType)&lt;br /&gt;##$fiResult = $Service.FindFolders($folderidcnt,$sfSearchFilter,$fvFolderView)&lt;br /&gt;$fiResult = $Service.FindFolders($folderidcnt,$fvFolderView)&lt;br /&gt;foreach($ffFolder in $fiResult.Folders){&lt;br /&gt; $TotalItemCount =  $TotalItemCount + $ffFolder.TotalCount;&lt;br /&gt; $FolderSize = $null;&lt;br /&gt; if ($ffFolder.TryGetProperty($PR_MESSAGE_SIZE_EXTENDED,[ref] $FolderSize))&lt;br /&gt; {&lt;br /&gt; $TotalItemSize = $TotalItemSize + [Int64]$FolderSize&lt;br /&gt; }&lt;br /&gt; $DeletedItemFolderSize = $null;&lt;br /&gt; if ($ffFolder.TryGetProperty($PR_DELETED_MESSAGE_SIZE_EXTENDED, [ref] $DeletedItemFolderSize))&lt;br /&gt; {&lt;br /&gt;  $TotalDeletedItemSize = $TotalDeletedItemSize + [Int64]$DeletedItemFolderSize      &lt;br /&gt; }&lt;br /&gt; $DeletedMsgCount = $null;&lt;br /&gt; if ($ffFolder.TryGetProperty($PR_DELETED_MSG_COUNT, [ref] $DeletedMsgCount))&lt;br /&gt;{&lt;br /&gt;  $TotalDeletedItemCount = $TotalDeletedItemCount + [Int32]$DeletedMsgCount;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;$rptobj = "" | select DisplayName,LegacyDN,TotalItemSize,TotalItemCount,TotalDeletedItemSize,TotalDeletedItemCount&lt;br /&gt;$rptobj.DisplayName = $_.DisplayName&lt;br /&gt;$rptobj.LegacyDN = $_.LegacyExchangeDN&lt;br /&gt;$rptobj.TotalItemCount = $TotalItemCount&lt;br /&gt;$rptobj.TotalItemSize  = $TotalItemSize&lt;br /&gt;$rptobj.TotalDeletedItemSize = $TotalDeletedItemSize&lt;br /&gt;$rptobj.TotalDeletedItemCount = $TotalDeletedItemCount&lt;br /&gt;$rptCollection += $rptobj&lt;br /&gt;&lt;br /&gt;$rptCollection&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-6539732590360746610?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/6539732590360746610/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=6539732590360746610' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6539732590360746610'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6539732590360746610'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2011/01/calculating-mailbox-sizes-using.html' title='Calculating Mailbox Sizes using Exchange Web Services and Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-4367734287118755530</id><published>2010-12-28T09:39:00.009+11:00</published><updated>2010-12-28T21:04:23.116+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='autodiscover'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='oab'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2007'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Module'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Testing AutoDiscover and the OAB age using Powershell and the EWS Managed API</title><content type='html'>One useful alternative to using the ubiquitous &lt;a href="http://technet.microsoft.com/en-us/library/bb124805.aspx"&gt;test-outlookwebservice&lt;/a&gt; cmdlet or &lt;a href="https://www.testexchangeconnectivity.com/"&gt;https://www.testexchangeconnectivity.com/&lt;/a&gt; for testing Autodiscover from powershell is to make use of the EWS Managed API and the verbose tracing feature this client side API offers. When you enable tracing on the &lt;span style="font-style:italic;"&gt;ExchangeService &lt;span style="font-style:italic;"&gt;&lt;/span&gt;&lt;/span&gt;object with the EWS Managed API you will then see the discovery process and the requests that are made to Autodiscover echo'd to the cmdline. This can add a new dimension to trying to diagnose an autodiscover problem that some of these other tools don't offer as you get to see both sides of the conversation. &lt;br /&gt;&lt;br /&gt; A simple autodiscover test script for the EWS 1.1 Managed API looks like&lt;br /&gt;&lt;br /&gt;$emailAddress = "Glen@domain.com"&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)&lt;br /&gt;$service.traceenabled = $true&lt;br /&gt;$service.Credentials = New-Object System.Net.NetworkCredential("username","password")&lt;br /&gt;$service.AutodiscoverUrl($emailAddress,{$true})&lt;br /&gt;&lt;br /&gt;The credential line is optional if you can use the currently logged on credentials just get rid of this line.&lt;br /&gt;&lt;br /&gt; An example using the EWS Powershell module i posted about &lt;a href="http://gsexdev.blogspot.com/2010/12/exchange-ews-powershell-module-for-ews.html"&gt;here&lt;/a&gt; we can reduce everything to one line&lt;br /&gt; &lt;br /&gt;New-MessageOps.EWSProfile -id Glen@domain.com -EnableTracing $true&lt;br /&gt;&lt;br /&gt; One other thing we've done with the module is to create specific cmdlets that make an autodiscover request outside of using the Managed API and the parse the result into a custom object so this information can then be easily displayed, exported or used in another application or test. One example where this can be useful is for seeing when the last time the Outlook Address Book was modified. In a normal powershell script you could do this using a HEAD command against the OABurl that shouldn't change much and get the lastmodified header. eg&lt;br /&gt;&lt;br /&gt;$url = New-Object System.Uri("https://autodiscover-red001.mail.microsoftonline.com/OAB/4fa96c9b-8232-46a3-b329-d03662dc9484/oab.xml")&lt;br /&gt;$htmlRequest = [System.Net.WebRequest]::Create($url)&lt;br /&gt;$htmlRequest.Method = "HEAD"&lt;br /&gt;$htmlRequest.Credentials = New-Object System.Net.NetworkCredential("user@domain","password")&lt;br /&gt;$htmlRequest.timeout = 100000&lt;br /&gt;$htmlRequest.ContentType = "text/xml"&lt;br /&gt;$htmlRequest.Headers.Add("Translate", "F")&lt;br /&gt;$htmlResponse = $htmlRequest.GetResponse()&lt;br /&gt;if ($htmlResponse.StatusCode -eq "OK"){&lt;br /&gt; $oabLastMod = $htmlResponse.GetResponseHeader("Last-Modified")&lt;br /&gt; $rsResponseStream = $htmlResponse.GetResponseStream();&lt;br /&gt; $oabLastMod &lt;br /&gt; $htmlRequest = $null&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;With the module this can be made simpler and dynamic to run in most environments by making use of autodiscover eg a two-liner&lt;br /&gt;&lt;br /&gt;$credential = get-credential&lt;br /&gt;Get-MessageOps.OABSetting -id Glen@domaim.com -credential $credential -oaburl (Get-MessageOps.AutoDiscover -id Glen@domaim.com -credential $credential | where-object {$_.type -eq "EXPR" -band $_.oaburl -ne $null}).oaburl&lt;br /&gt;&lt;br /&gt;If you want something that runs against BPOS there is a slightly different cmdlet which handles the different EntryPoints have a look at the sample post &lt;a href="http://www.messageops.com/determining-when-the-offline-address-book-was-last-updated"&gt;here&lt;/a&gt;. There are also different cmdlets for the different autodiscover entry points for liveEdu&lt;br /&gt;&lt;br /&gt;To get a copy of the powershell module I've talked about this can be downloaded from &lt;a href="http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip "&gt;http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-4367734287118755530?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/4367734287118755530/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=4367734287118755530' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/4367734287118755530'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/4367734287118755530'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/12/testing-autodiscover-and-oab-age-using.html' title='Testing AutoDiscover and the OAB age using Powershell and the EWS Managed API'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-9107504229351376568</id><published>2010-12-22T20:38:00.007+11:00</published><updated>2010-12-22T21:20:05.575+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Office365'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Using Remote Powershell and EWS on Office365</title><content type='html'>A big leap forward on Office365 compared with the current BPOS offering is the ability to use remote powershell and a subset of the Exchange cmdlets that are available in Exchange 2010. This makes it pretty easy to migrate your current onpremise scripts that use make use of EMS and EWS into something that uses remote powershell and EWS.  To demonstrate this I've converted on my old scripts the &lt;a href="http://gsexdev.blogspot.com/2010/03/freebusy-board-for-exchange-ews-managed.html"&gt;FreeBusy board&lt;/a&gt; to use Remote powershell, Office365 and the EWS Managed API 1.1.&lt;br /&gt;&lt;br /&gt;I've put a download of the script &lt;a href="http://msgdev.mvps.org/exdevblog/fb9to5v5.zip"&gt;here &lt;/a&gt;the code looks like&lt;br /&gt;&lt;sid="&gt;&lt;span style="font-size:78%;"&gt;&lt;br /&gt;$UserName = "admin@domain.com"&lt;br /&gt;$Password = "password1"&lt;br /&gt;$secpassword = ConvertTo-SecureString $Password -AsPlainText -Force&lt;br /&gt;$adminCredential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName,$secpassword  &lt;br /&gt;&lt;br /&gt;If(Get-PSSession | where-object {$_.ConfigurationName -eq "Microsoft.Exchange"}){&lt;br /&gt;    write-host "Session Exists"&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;    $rpRemotePowershell = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -credential $adminCredential  -Authentication Basic -AllowRedirection&lt;br /&gt;    $importresults = Import-PSSession $rpRemotePowershell&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)&lt;br /&gt;&lt;br /&gt;$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()&lt;br /&gt;$sidbind = "LDAP://&amp;lt;SID=" + $windowsIdentity.user.Value.ToString() + "&amp;gt;"&lt;br /&gt;$aceuser = [ADSI]$sidbind&lt;br /&gt;$service.Credentials = New-Object System.Net.NetworkCredential($username,$password)&lt;br /&gt;$service.AutodiscoverUrl($UserName ,{$true})&lt;br /&gt;&lt;br /&gt;$mbHash = @{ }&lt;br /&gt;&lt;br /&gt;$tmValHash = @{ }&lt;br /&gt;$tidx = 0&lt;br /&gt;for($vsStartTime=[DateTime]::Parse([DateTime]::Now.ToString("yyyy-MM-dd 0:00"));$vsStartTime -lt [DateTime]::Parse([DateTime]::Now.ToString("yyyy-MM-dd 0:00")).AddDays(1);$vsStartTime = $vsStartTime.AddMinutes(30)){&lt;br /&gt;    $tmValHash.add($vsStartTime.ToString("HH:mm"),$tidx)   &lt;br /&gt;    $tidx++&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;get-mailbox -ResultSize unlimited | foreach-object{&lt;br /&gt;    if ($mbHash.ContainsKey($_.WindowsEmailAddress.ToString()) -eq $false){&lt;br /&gt;        $mbHash.Add($_.WindowsEmailAddress.ToString(),$_.DisplayName)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;$Attendeesbatch = [activator]::createinstance(([type]'System.Collections.Generic.List`1').makegenerictype([Microsoft.Exchange.WebServices.Data.AttendeeInfo]))&lt;br /&gt;&lt;br /&gt;$StartTime = [DateTime]::Parse([DateTime]::Now.ToString("yyyy-MM-dd 0:00"))&lt;br /&gt;$EndTime = $StartTime.AddDays(1)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$displayStartTime =  [DateTime]::Parse([DateTime]::Now.ToString("yyyy-MM-dd 08:30"))&lt;br /&gt;$displayEndTime = [DateTime]::Parse([DateTime]::Now.ToString("yyyy-MM-dd 17:30"))&lt;br /&gt;&lt;br /&gt;$drDuration = new-object Microsoft.Exchange.WebServices.Data.TimeWindow($StartTime,$EndTime)&lt;br /&gt;$AvailabilityOptions = new-object Microsoft.Exchange.WebServices.Data.AvailabilityOptions&lt;br /&gt;$AvailabilityOptions.RequestedFreeBusyView = [Microsoft.Exchange.WebServices.Data.FreeBusyViewType]::DetailedMerged&lt;br /&gt;&lt;br /&gt;$batchsize = 100&lt;br /&gt;$bcount = 0&lt;br /&gt;$bresult = @()&lt;br /&gt;if ($mbHash.Count -ne 0){&lt;br /&gt;    $mbHash.GetEnumerator() | Sort Value | foreach-object {&lt;br /&gt;        if ($bcount -ne $batchsize){&lt;br /&gt;            $Attendee1 = new-object Microsoft.Exchange.WebServices.Data.AttendeeInfo($_.Key)&lt;br /&gt;            $Attendeesbatch.add($Attendee1)&lt;br /&gt;            $bcount++&lt;br /&gt;        }&lt;br /&gt;        else{&lt;br /&gt;            $availresponse = $service.GetUserAvailability($Attendeesbatch,$drDuration,[Microsoft.Exchange.WebServices.Data.AvailabilityData]::FreeBusy,$AvailabilityOptions)&lt;br /&gt;            foreach($avail in $availresponse.AttendeesAvailability.OverallResult){$bresult += $avail}&lt;br /&gt;            $Attendeesbatch = [activator]::createinstance(([type]'System.Collections.Generic.List`1').makegenerictype([Microsoft.Exchange.WebServices.Data.AttendeeInfo]))&lt;br /&gt;            $bcount = 0&lt;br /&gt;            $Attendee1 = new-object Microsoft.Exchange.WebServices.Data.AttendeeInfo($_.Key)&lt;br /&gt;            $Attendeesbatch.add($Attendee1)&lt;br /&gt;            $bcount++&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;$availresponse = $service.GetUserAvailability($Attendeesbatch,$drDuration,[Microsoft.Exchange.WebServices.Data.AvailabilityData]::FreeBusy,$AvailabilityOptions)&lt;br /&gt;$usrIdx = 0&lt;br /&gt;$frow = $true&lt;br /&gt;foreach($res in $availresponse.AttendeesAvailability){&lt;br /&gt;      if ($frow -eq $true){&lt;br /&gt;        $fbBoard = $fbBoard + "&amp;lt;table&amp;gt;&amp;lt;tr bgcolor=`"#95aedc`"&amp;gt;" +"`r`n"&lt;br /&gt;        $fbBoard = $fbBoard + "&amp;lt;td align=`"center`" style=`"width=200;`" &amp;gt;&amp;lt;b&amp;gt;User&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;" +"`r`n"&lt;br /&gt;        for($stime = $displayStartTime;$stime -lt $displayEndTime;$stime = $stime.AddMinutes(30)){&lt;br /&gt;            $fbBoard = $fbBoard + "&amp;lt;td align=`"center`" style=`"width=50;`" &amp;gt;&amp;lt;b&amp;gt;" + $stime.ToString("HH:mm") + "&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;" +"`r`n"&lt;br /&gt;        }&lt;br /&gt;        $fbBoard = $fbBoard + "&amp;lt;/tr&amp;gt;" + "`r`n"&lt;br /&gt;        $frow = $false&lt;br /&gt;    }&lt;br /&gt;    for($stime = $displayStartTime;$stime -lt $displayEndTime;$stime = $stime.AddMinutes(30)){&lt;br /&gt;        if ($stime -eq $displayStartTime){&lt;br /&gt;            $fbBoard = $fbBoard + "&amp;lt;td bgcolor=`"#CFECEC`"&amp;gt;&amp;lt;b&amp;gt;" + $mbHash[$Attendeesbatch[$usrIdx].SmtpAddress] + "&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;"  + "`r`n"&lt;br /&gt;        }&lt;br /&gt;        $title = "title="&lt;br /&gt;        if ($res.MergedFreeBusyStatus[$tmValHash[$stime.ToString("HH:mm")]] -ne $null){&lt;br /&gt;            $gdet = $false&lt;br /&gt;            $FbValu = $res.MergedFreeBusyStatus[$tmValHash[$stime.ToString("HH:mm")]]&lt;br /&gt;            switch($FbValu.ToString()){&lt;br /&gt;                "Free" {$bgColour = "bgcolor=`"#41A317`""}&lt;br /&gt;                "Tentative" {$bgColour = "bgcolor=`"#52F3FF`""&lt;br /&gt;                         $gdet = $true&lt;br /&gt;                    }&lt;br /&gt;                "Busy" {$bgColour = "bgcolor=`"#153E7E`""&lt;br /&gt;                         $gdet = $true&lt;br /&gt;                    }&lt;br /&gt;                "OOF" {$bgColour = "bgcolor=`"#4E387E`""&lt;br /&gt;                         $gdet = $true&lt;br /&gt;                    }&lt;br /&gt;                "NoData" {$bgColour = "bgcolor=`"#98AFC7`""}&lt;br /&gt;                "N/A" {$bgColour = "bgcolor=`"#98AFC7`""}       &lt;br /&gt;            }&lt;br /&gt;            if ($gdet -eq $true){&lt;br /&gt;                if ($res.CalendarEvents.Count -ne 0){&lt;br /&gt;                    for($ci=0;$ci -lt $res.CalendarEvents.Count;$ci++){&lt;br /&gt;                        if ($res.CalendarEvents[$ci].StartTime -ge $stime -band $stime -le $res.CalendarEvents[$ci].EndTime){               &lt;br /&gt;                            if($res.CalendarEvents[$ci].Details.IsPrivate -eq $False){&lt;br /&gt;                                $subject = ""&lt;br /&gt;                                $location = ""&lt;br /&gt;                                if ($res.CalendarEvents[$ci].Details.Subject -ne $null){&lt;br /&gt;                                    $subject = $res.CalendarEvents[$ci].Details.Subject.ToString()&lt;br /&gt;                                }&lt;br /&gt;                                if ($res.CalendarEvents[$ci].Details.Location -ne $null){&lt;br /&gt;                                    $location = $res.CalendarEvents[$ci].Details.Location.ToString()&lt;br /&gt;                                }&lt;br /&gt;                                $title = $title + "`"" + $subject + " " + $location + "`" "&lt;br /&gt;                            }&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;           &lt;br /&gt;        }&lt;br /&gt;        else{&lt;br /&gt;            $bgColour = "bgcolor=`"#98AFC7`""&lt;br /&gt;        }&lt;br /&gt;        if($title -ne "title="){&lt;br /&gt;            $fbBoard = $fbBoard + "&amp;lt;td " + $bgColour + " " + $title + "&amp;gt;&amp;lt;/td&amp;gt;"  + "`r`n"&lt;br /&gt;        }&lt;br /&gt;        else{&lt;br /&gt;            $fbBoard = $fbBoard + "&amp;lt;td " + $bgColour + "&amp;gt;&amp;lt;/td&amp;gt;"  + "`r`n"&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;    $fbBoard = $fbBoard + "&amp;lt;/tr&amp;gt;"  + "`r`n"&lt;br /&gt;    $usrIdx++&lt;br /&gt;}&lt;br /&gt;$fbBoard = $fbBoard + "&amp;lt;/table&amp;gt;"  + "  "&lt;br /&gt;$fbBoard | out-file "c:\fbboard.htm"&lt;/span&gt;&lt;br /&gt;&lt;/sid="&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-9107504229351376568?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/9107504229351376568/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=9107504229351376568' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/9107504229351376568'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/9107504229351376568'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/12/using-remote-powershell-and-ews-in.html' title='Using Remote Powershell and EWS on Office365'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-6735136778040064425</id><published>2010-12-15T21:40:00.007+11:00</published><updated>2010-12-16T10:07:00.036+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Module'/><title type='text'>Exchange EWS Powershell module for the EWS Managed API</title><content type='html'>One of the constant challenges in IT especially where scripting is involved is abstracting things that seem complicated and trying to make them easier. Because what we do a lot of the time are slightly different iterations of the same idea making simpler these repetitions can be a good thing. The EWS Managed API is a great tools for making it easier to access Exchange using powershell and other .NET languages. One of the freelance projects I've been working on over the past couple of months was firstly a powershell snapin just for BPOS that we have now turned this into a Powershell module that will work with any version of on premise Exchange (Starting with 2007) as well as BPOS and Office365. This module contains a bunch of growing cmdlets that help automate what would generally be a large number of lines of script within a normal EWS powershell script down to a one or two lines. The advantage of this was making it easy to reuse large chucks of code in simpler scripts to do more complicated tasks. Because it uses the EWS Managed API it exposes these objects and methods so you can mix and match between using the cmdlets and just pure Managed API code. Fortunately &lt;a href="http://www.messageops.com/"&gt;MessageOps &lt;/a&gt;who i wrote this for (and have a great array of other apps) have decided to provide it free to everyone to use. This is still a work in process so there are a few bugs here and there and the documentation is a little sparse but for the most it works pretty well you can download the module and some instructions and examples of how to use it from &lt;a href="http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip" target="_blank"&gt;&lt;span class="yshortcuts" id="lw_1292412040_3"&gt;http://www.messageops.com/downloads/MessageOps-Exchange-Module.zip&lt;/span&gt;&lt;/a&gt; . As an example of what it can do here's how easy you can use this to create RSS feeds from Inbox or Public folder Items&lt;br /&gt;&lt;br /&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;o:officedocumentsettings&gt;   &lt;o:allowpng/&gt;  &lt;/o:OfficeDocumentSettings&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:trackmoves/&gt;   &lt;w:trackformatting/&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:donotpromoteqf/&gt;   &lt;w:lidthemeother&gt;EN-AU&lt;/w:LidThemeOther&gt;   &lt;w:lidthemeasian&gt;X-NONE&lt;/w:LidThemeAsian&gt;   &lt;w:lidthemecomplexscript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:splitpgbreakandparamark/&gt;    &lt;w:enableopentypekerning/&gt;    &lt;w:dontflipmirrorindents/&gt;    &lt;w:overridetablestylehps/&gt;   &lt;/w:Compatibility&gt;   &lt;m:mathpr&gt;    &lt;m:mathfont val="Cambria Math"&gt;    &lt;m:brkbin val="before"&gt;    &lt;m:brkbinsub val="&amp;#45;-"&gt;    &lt;m:smallfrac val="off"&gt;    &lt;m:dispdef/&gt;    &lt;m:lmargin val="0"&gt;    &lt;m:rmargin val="0"&gt;    &lt;m:defjc val="centerGroup"&gt;    &lt;m:wrapindent val="1440"&gt;    &lt;m:intlim val="subSup"&gt;    &lt;m:narylim val="undOvr"&gt;   &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" defunhidewhenused="true" defsemihidden="true" defqformat="false" defpriority="99" latentstylecount="267"&gt;   &lt;w:lsdexception locked="false" priority="0" semihidden="false" unhidewhenused="false" qformat="true" name="Normal"&gt;   &lt;w:lsdexception locked="false" priority="9" semihidden="false" unhidewhenused="false" qformat="true" name="heading 1"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 2"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 3"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 4"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 5"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 6"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 7"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 8"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 9"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 1"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 2"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 3"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 4"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 5"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 6"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 7"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 8"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 9"&gt;   &lt;w:lsdexception locked="false" priority="35" qformat="true" name="caption"&gt;   &lt;w:lsdexception locked="false" priority="10" semihidden="false" unhidewhenused="false" qformat="true" name="Title"&gt;   &lt;w:lsdexception locked="false" priority="1" name="Default Paragraph Font"&gt;   &lt;w:lsdexception locked="false" priority="11" semihidden="false" unhidewhenused="false" qformat="true" name="Subtitle"&gt;   &lt;w:lsdexception locked="false" priority="22" semihidden="false" unhidewhenused="false" qformat="true" name="Strong"&gt;   &lt;w:lsdexception locked="false" priority="20" semihidden="false" unhidewhenused="false" qformat="true" name="Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="59" semihidden="false" unhidewhenused="false" name="Table Grid"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Placeholder Text"&gt;   &lt;w:lsdexception locked="false" priority="1" semihidden="false" unhidewhenused="false" qformat="true" name="No Spacing"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Revision"&gt;   &lt;w:lsdexception locked="false" priority="34" semihidden="false" unhidewhenused="false" qformat="true" name="List Paragraph"&gt;   &lt;w:lsdexception locked="false" priority="29" semihidden="false" unhidewhenused="false" qformat="true" name="Quote"&gt;   &lt;w:lsdexception locked="false" priority="30" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Quote"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="19" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="21" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="31" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Reference"&gt;   &lt;w:lsdexception locked="false" priority="32" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Reference"&gt;   &lt;w:lsdexception locked="false" priority="33" semihidden="false" unhidewhenused="false" qformat="true" name="Book Title"&gt;   &lt;w:lsdexception locked="false" priority="37" name="Bibliography"&gt;   &lt;w:lsdexception locked="false" priority="39" qformat="true" name="TOC Heading"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable  {mso-style-name:"Table Normal";  mso-tstyle-rowband-size:0;  mso-tstyle-colband-size:0;  mso-style-noshow:yes;  mso-style-priority:99;  mso-style-parent:"";  mso-padding-alt:0cm 5.4pt 0cm 5.4pt;  mso-para-margin-top:0cm;  mso-para-margin-right:0cm;  mso-para-margin-bottom:10.0pt;  mso-para-margin-left:0cm;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:"Calibri","sans-serif";  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;  mso-bidi-font-family:"Times New Roman";  mso-bidi-theme-font:minor-bidi;  mso-fareast-language:EN-US;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;div style="border-width: medium medium 1pt; border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(79, 129, 189); padding: 0cm 0cm 4pt;"&gt;  &lt;p class="MsoTitle"&gt;Using the MessageOps Exchange PowerShell Module to generate a RSS feeds of a specific mailbox folder or public folder in Exchange.&lt;/p&gt;  &lt;/div&gt;  &lt;p class="MsoNormal"&gt;The EWS Powershell module contains Out-MessageOps.MessagesToRSS cmdlet that will output a collection of EWS Messages Items to a RSS feed. To get the Collection of Items to Output to the RSS Feed you can use one either one of the following 3 cmdlets which will retrieve Items from a Mailbox or public folder.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Get-MessageOps.Messages : This is a generic retrieve and simple search cmdlets that returns messages and message details from a mailbox. Supports several switches to find messages based on Subject, Read Status, Attachments, etc. It returns information such as message recipients, sender information, message headers, message body, and attachment details.&lt;/p&gt;&lt;p&gt; Search-&lt;span style="font-size:100%;"&gt;MessageOps.MailFolder : &lt;/span&gt;&lt;span style="font-size:100%;"&gt; &lt;/span&gt;&lt;span style="font-size:100%;"&gt;Allows you to search a mailbox folder based on a number or parameters such as StartDate, EndDate, Subject &lt;span style=";font-family:arial;font-size:100%;"  &gt;Contains, Body Contains.&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;Search-MessageOps.CrawlMailFolder :&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;span style="font-size:100%;"&gt;Allows more advanced searching of mailboxes. Allows you to use Regular Expressions in mailbox searches. Includes a built in Credit Card search function.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Which cmdlet you use depends on what your trying to achieve and how detailed the filtering you want to apply to the collection of messages you want in the RSS feed. Examples of using this with the different cmdlets&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Before you start you need a EWSProfile object to create one use the following&lt;/p&gt;  &lt;p class="MsoNormal"&gt;$ewsProfile = New-MessageOps.EWSProfile -id “&lt;a href="mailto:user@.domain.com"&gt;user@.domain.com&lt;/a&gt;”&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Creating a feed of the last 20 items in the Inbox&lt;/p&gt;  &lt;p class="MsoNormal"&gt;$ItemCollection = Get-MessageOps.Messages -p $ewsprofile -fp "\\Inbox" -messagecount 20 -fulldetails $true &lt;/p&gt;  &lt;p class="MsoNormal"&gt;Out-MessageOps.MessagesToRSS -p $ewsprofile -FileName c:\outrss.xml -FeedTitle "Mailbox Feed" -Items $ItemCollection&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Create a feed of the last 20 Items in Public Folder called company-emails&lt;/p&gt;  &lt;p class="MsoNormal"&gt;$ItemCollection = Get-MessageOps.Messages -p $ewsprofile -fp "\\publicfolderroot\company-emails" -messagecount 20 -fulldetails $true &lt;/p&gt;  &lt;p class="MsoNormal"&gt;Out-MessageOps.MessagesToRSS -p $ewsprofile -FileName c:\outrsspf.xml -FeedTitle "Public Folder Feed" -Items $ItemCollection -PublicFolder $true&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Create a feed of just email from a specific address &lt;/p&gt;  &lt;p class="MsoNormal"&gt;$ItemCollection =&lt;span style=""&gt;  &lt;/span&gt;Search-MessageOps.MailFolder -p $ewsprofile -fp \\inbox -from bob@domain.com -fulldetail $true -messagecount 20 -fulldetails $true &lt;/p&gt;  &lt;p class="MsoNormal"&gt;Out-MessageOps.MessagesToRSS -p $ewsprofile -FileName c:\outrs22s.xml -FeedTitle "Mailbox Feed" -Items $ItemCollection -PublicFolder $true&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Using different options for unread email, attachments or use your own custom EWS Managed API searchfilter object can allow you to create any custom filter to suit most needs.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-6735136778040064425?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/6735136778040064425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=6735136778040064425' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6735136778040064425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6735136778040064425'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/12/exchange-ews-powershell-module-for-ews.html' title='Exchange EWS Powershell module for the EWS Managed API'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-581276109990965091</id><published>2010-12-01T13:51:00.005+11:00</published><updated>2010-12-01T15:58:07.148+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2007'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Simple Exchange Powershell Client V2</title><content type='html'>This has taken me a little longer then expected to update but I've finally created a version 2 of my simple powershell client script i posted &lt;a href="http://gsexdev.blogspot.com/2009/06/simple-exchange-email-client-for.html"&gt;here&lt;/a&gt;. &lt;div&gt; &lt;/div&gt;&lt;div&gt;&lt;br /&gt;Firstly if you missed it the new version the EWS Managed API 1.1 has been released which allows you to access all the new 2010 SP1 functionality like archive mailboxes, dumpster v2 etc you can download this from &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c3342fb3-fbcc-4127-becf-872c746840e1"&gt;here&lt;/a&gt; the new script requires this library.&lt;br /&gt;&lt;br /&gt;The new features I've added to the script is firstly there is a Entry Point box that allows you to select what entry point you want.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_a4Go8x--KMQ/TPW8eAZFE7I/AAAAAAAAACk/F7Cgnf27sys/s1600/epoint.PNG"&gt;&lt;img style="cursor: pointer; width: 486px; height: 40px;" src="http://1.bp.blogspot.com/_a4Go8x--KMQ/TPW8eAZFE7I/AAAAAAAAACk/F7Cgnf27sys/s320/epoint.PNG" alt="" id="BLOGGER_PHOTO_ID_5545545739863921586" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The Non IPM Root is usefull if you want to look at the dumpster folders or other things in the Non_IPM_Root, Archive root takes you into the Archive mailbox if its exists for that user.&lt;br /&gt;&lt;br /&gt;Another new edition is the ItemType box which allows you the select between being able to view the Normal Mailbox Items, FAI (Folder Associated Items) or Deleted Items (not really applicable for Dumpster v2).&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_a4Go8x--KMQ/TPXPRNnItqI/AAAAAAAAACs/zilFByCNVUA/s1600/mtype.PNG"&gt;&lt;img style="cursor: pointer; width: 493px; height: 73px;" src="http://4.bp.blogspot.com/_a4Go8x--KMQ/TPXPRNnItqI/AAAAAAAAACs/zilFByCNVUA/s320/mtype.PNG" alt="" id="BLOGGER_PHOTO_ID_5545566410795169442" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Lastly because the new script is built for use with Windows 7.0 and Powershell V2 the right click menu for the datagird will now work okay so I've added the ability to once you select the Items in the datagrid you can rightclick and then  Delete, Copy or Move the selected Items to another folder (the deletes are soft deletes).&lt;br /&gt;&lt;br /&gt;I've put a download of the new script&lt;a href="http://msgdev.mvps.org/exdevblog/secv2.zip"&gt; here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-581276109990965091?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/581276109990965091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=581276109990965091' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/581276109990965091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/581276109990965091'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/12/simple-exchange-powershell-client-v2.html' title='Simple Exchange Powershell Client V2'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_a4Go8x--KMQ/TPW8eAZFE7I/AAAAAAAAACk/F7Cgnf27sys/s72-c/epoint.PNG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-3442274066764528938</id><published>2010-11-16T13:18:00.004+11:00</published><updated>2010-11-16T15:57:00.087+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Audit'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><title type='text'>Breadcrumb auditing in Exchange 2010 with EWS and Powershell</title><content type='html'>Great strides have been made since Exchange 2007 SP2 with the introduction of more advanced audit levels into Exchange which have again improved in Exchange 2010 and again with 2010 SP1. Auditing however relies on a few things that after the fact of an event you may have wished to audit (or more likely a Superior wanting to know what mailboxes where accessed) .  But like footprints in the sand when you walk along the beach many of the actions we do in Outlook do leave marks that the majority of people may not realize. One such mark in the sand that happens in your mailbox when using Outlook 2010 or OWA 2010 is when you access another users folder eg calendar, contacts etc is  a wunderbar link gets added to the Common Views Root folder.&lt;br /&gt;&lt;br /&gt;What you can do with this little bit of information is deduce what other mailboxes a particular user has been access by enumerating the wunderbar links in the users common view folder. These wunderbar links are FAI (folder associated Items) so live in the FAI collection of that particular folder.&lt;br /&gt;&lt;br /&gt;To do this with EWS requires the use of some of the nice new features of EWS in Exchange 2010 such as the ability to access the associated Folder Items collection where these WunderBar Shortcuts are stored.&lt;br /&gt;&lt;br /&gt;To access the associated folder Items collection in EWS you just need to change the Traversal type to Associated (note this wont work on 2007).&lt;br /&gt;&lt;br /&gt;The Wunderbar Items themselves have a bunch of extended properties that contain information that is important to see what mailbox and folder this users was accessing. A full list of the shortcut properties can be found in the following Exchange protocol document &lt;a href="http://msdn.microsoft.com/en-us/library/cc463899%28EXCHG.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc463899%28EXCHG.80%29.aspx&lt;/a&gt;. The Ones I've used in this script are&lt;br /&gt;&lt;br /&gt;PidTagWlinkEntryId   EntryID the ShortCut points to&lt;br /&gt;PidTagWlinkStoreEntryId  StoreEntryID the ShortCut points to&lt;br /&gt;PidTagWlinkAddressBookEID Like the above but contains just the users info&lt;br /&gt;PidTagWlinkFolderType Contains the GUID to let you know what type of folder it is&lt;br /&gt;PidTagWlinkGroupName The name of the group&lt;br /&gt;&lt;br /&gt;I've put this altogether is a powershell script that use the new &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=4dc3a3ee-ce20-4bd4-afbf-4d28fa875a2d"&gt;EWS 1.1 Managed API beta&lt;/a&gt; (which allows you to access the associated folders collection). To use this script you need to customize the the following variable the output of this script is a html report.&lt;br /&gt;&lt;br /&gt;$casserverName = "casservername"&lt;br /&gt;$userName = "username"&lt;br /&gt;$password = "password"&lt;br /&gt;$domain = "domain"&lt;br /&gt;$Mailboxname = "user@domain.com"&lt;br /&gt;$fileName = "c:\report.htm"&lt;br /&gt;&lt;br /&gt;I've put a download of this script &lt;a href="http://msgdev.mvps.org/exdevblog/bcrumbaudit.zip"&gt;here &lt;/a&gt;the script itself looks like.&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;$casserverName = "casservername"&lt;br /&gt;$userName = "username"&lt;br /&gt;$password = "password"&lt;br /&gt;$domain = "domain"&lt;br /&gt;$Mailboxname = "user@domain.com"&lt;br /&gt;$fileName = "c:\report.htm"&lt;br /&gt;&lt;br /&gt;$rptCollection = @()&lt;br /&gt;&lt;br /&gt;function ReturnFolderType($guid){&lt;br /&gt;    switch($guid){&lt;br /&gt;        "0C78060000000000C000000000000046" { return "MailFolder"}&lt;br /&gt;        "0278060000000000C000000000000046" { return "Calendar" }&lt;br /&gt;        "0178060000000000C000000000000046" { return "Contacts" }&lt;br /&gt;        "0378060000000000C000000000000046" { return "Tasks"}&lt;br /&gt;        "0478060000000000C000000000000046" { return "Notes"}&lt;br /&gt;        "0878060000000000C000000000000046" { return "Journal"}&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## Code From http://poshcode.org/624&lt;br /&gt;## Create a compilation environment&lt;br /&gt;$Provider=New-Object Microsoft.CSharp.CSharpCodeProvider&lt;br /&gt;$Compiler=$Provider.CreateCompiler()&lt;br /&gt;$Params=New-Object System.CodeDom.Compiler.CompilerParameters&lt;br /&gt;$Params.GenerateExecutable=$False&lt;br /&gt;$Params.GenerateInMemory=$True&lt;br /&gt;$Params.IncludeDebugInformation=$False&lt;br /&gt;$Params.ReferencedAssemblies.Add("System.DLL") | Out-Null&lt;br /&gt;&lt;br /&gt;$TASource=@'&lt;br /&gt;  namespace Local.ToolkitExtensions.Net.CertificatePolicy{&lt;br /&gt;    public class TrustAll : System.Net.ICertificatePolicy {&lt;br /&gt;      public TrustAll() {&lt;br /&gt;      }&lt;br /&gt;      public bool CheckValidationResult(System.Net.ServicePoint sp,&lt;br /&gt;        System.Security.Cryptography.X509Certificates.X509Certificate cert,&lt;br /&gt;        System.Net.WebRequest req, int problem) {&lt;br /&gt;        return true;&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;'@&lt;br /&gt;$TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)&lt;br /&gt;$TAAssembly=$TAResults.CompiledAssembly&lt;br /&gt;&lt;br /&gt;## We now create an instance of the TrustAll and attach it to the ServicePointManager&lt;br /&gt;$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")&lt;br /&gt;[System.Net.ServicePointManager]::CertificatePolicy=$TrustAll&lt;br /&gt;&lt;br /&gt;## end code from http://poshcode.org/624&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)&lt;br /&gt;$uri=[system.URI] ("https://" + $casserverName + "/ews/exchange.asmx")&lt;br /&gt;$service.Url = $uri&lt;br /&gt;$service.Credentials = New-Object System.Net.NetworkCredential($username,$password,$domain)&lt;br /&gt;$rfFolderid  = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)&lt;br /&gt;$fview = New-Object Microsoft.Exchange.WebServices.Data.FolderView(1000)&lt;br /&gt;$Sfir = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName, "Common Views")&lt;br /&gt;$findfldResults = $Service.FindFolders($rfFolderid,$Sfir,$fview)&lt;br /&gt;if ($findfldResults.Folders.Count -eq 1) {&lt;br /&gt;    $findfldResults.Folders[0].DisplayName&lt;br /&gt;        $PidTagWlinkEntryId = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26700, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)&lt;br /&gt;        $PidTagWlinkStoreEntryId = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26702, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)&lt;br /&gt;    $PidTagWlinkAddressBookEID = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26708, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)&lt;br /&gt;    $PidTagWlinkFolderType = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26703, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)&lt;br /&gt;    $PidTagWlinkGroupName = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26705, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)&lt;br /&gt;    $Propset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)&lt;br /&gt;    $Propset.add($PidTagWlinkEntryId)&lt;br /&gt;    $Propset.add($PidTagWlinkStoreEntryId)&lt;br /&gt;    $Propset.add($PidTagWlinkAddressBookEID)&lt;br /&gt;    $Propset.add($PidTagWlinkFolderType)&lt;br /&gt;    $Propset.add($PidTagWlinkGroupName)&lt;br /&gt;    $iv = New-Object Microsoft.Exchange.WebServices.Data.ItemView(10000)&lt;br /&gt;        $iv.PropertySet = $Propset&lt;br /&gt;        $iv.Traversal = [Microsoft.Exchange.WebServices.Data.ItemTraversal]::Associated&lt;br /&gt;        $fiResults = $findfldResults.Folders[0].FindItems($iv)&lt;br /&gt;    foreach($itItem in $fiResults.Items){&lt;br /&gt;        $itItem.Subject&lt;br /&gt;        $WlinkStoreEntryId = $null&lt;br /&gt;        $rptobj = "" | select MailboxName,LinkName,GroupName,FolderType,DateCreated,LastModified&lt;br /&gt;        $lnLegDN = ""&lt;br /&gt;        if ($itItem.TryGetProperty($PidTagWlinkStoreEntryId,[ref]$WlinkStoreEntryId))&lt;br /&gt;                    {&lt;br /&gt;           &lt;br /&gt;                        $leLegDnStart = 0&lt;br /&gt;                         for ($ssArraynum = (([byte[]]$WlinkStoreEntryId).Length - 2); $ssArraynum -ne 0; $ssArraynum--)&lt;br /&gt;                        {&lt;br /&gt;                            if (([byte[]]$WlinkStoreEntryId)[$ssArraynum] -eq 0)&lt;br /&gt;                            {&lt;br /&gt;                                $leLegDnStart = $ssArraynum;&lt;br /&gt;                                $lnLegDN = [System.Text.ASCIIEncoding]::ASCII.GetString(([byte[]]$WlinkStoreEntryId), $leLegDnStart + 1, (([byte[]]$WlinkStoreEntryId).Length - ($leLegDnStart + 2)));&lt;br /&gt;                                $ssArraynum = 1;&lt;br /&gt;                            }&lt;br /&gt;                        }&lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;        else{&lt;br /&gt;            if ($itItem.TryGetProperty($PidTagWlinkAddressBookEID,[ref]$WlinkStoreEntryId))&lt;br /&gt;                    {&lt;br /&gt;           &lt;br /&gt;                        $leLegDnStart = 0&lt;br /&gt;                        $lnLegDN = ""&lt;br /&gt;                        for ($ssArraynum = (([byte[]]$WlinkStoreEntryId).Length - 2); $ssArraynum -ne 0; $ssArraynum--)&lt;br /&gt;                        {&lt;br /&gt;                            if (([byte[]]$WlinkStoreEntryId)[$ssArraynum] -eq 0)&lt;br /&gt;                            {&lt;br /&gt;                                $leLegDnStart = $ssArraynum;&lt;br /&gt;                                $lnLegDN = [System.Text.ASCIIEncoding]::ASCII.GetString(([byte[]]$WlinkStoreEntryId), $leLegDnStart + 1, (([byte[]]$WlinkStoreEntryId).Length - ($leLegDnStart + 2)));&lt;br /&gt;                                $ssArraynum = 1;&lt;br /&gt;                            }&lt;br /&gt;                        }&lt;br /&gt;        }   &lt;br /&gt;           &lt;br /&gt;        }&lt;br /&gt;        if($lnLegDN -ne ""){&lt;br /&gt;        $ncCol = $service.ResolveName($lnLegDN)&lt;br /&gt;        $mbox = ""&lt;br /&gt;                foreach ($NameResolution in $ncCol)&lt;br /&gt;                {&lt;br /&gt;                     $mbox = $NameResolution.Mailbox.Address&lt;br /&gt;                }&lt;br /&gt;        $FolderType = $null&lt;br /&gt;        if ($itItem.TryGetProperty($PidTagWlinkFolderType,[ref]$FolderType)){&lt;br /&gt;            $hexArr = $FolderType | ForEach-Object { $_.ToString("X2") }&lt;br /&gt;                        $hexString = $hexArr -join ''&lt;br /&gt;            $rptobj.FolderType = ReturnFolderType($hexString)&lt;br /&gt;            $hexString&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;        $GroupName = $null&lt;br /&gt;        if ($itItem.TryGetProperty($PidTagWlinkGroupName,[ref]$GroupName)){&lt;br /&gt;            $rptobj.GroupName = $GroupName&lt;br /&gt;        }&lt;br /&gt;        $rptobj.MailboxName = $mbox&lt;br /&gt;        $rptobj.LinkName = $itItem.Subject&lt;br /&gt;        $rptobj.DateCreated = $itItem.DateTimeCreated&lt;br /&gt;        $rptobj.LastModified = $itItem.LastModifiedTime&lt;br /&gt;        $rptCollection += $rptobj}&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;$rptCollection&lt;br /&gt;$tableStyle = @"&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;BODY{background-color:white;}&lt;br /&gt;TABLE{border-width: 1px;&lt;br /&gt;  border-style: solid;&lt;br /&gt;  border-color: black;&lt;br /&gt;  border-collapse: collapse;&lt;br /&gt;}&lt;br /&gt;TH{border-width: 1px;&lt;br /&gt;  padding: 10px;&lt;br /&gt;  border-style: solid;&lt;br /&gt;  border-color: black;&lt;br /&gt;  background-color:#66CCCC&lt;br /&gt;}&lt;br /&gt;TD{border-width: 1px;&lt;br /&gt;  padding: 2px;&lt;br /&gt;  border-style: solid;&lt;br /&gt;  border-color: black;&lt;br /&gt;  background-color:white&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;"@&lt;br /&gt; &lt;br /&gt;$body = @"&lt;br /&gt;&amp;lt;p style="font-size:25px;family:calibri;color:#ff9100"&amp;gt;&lt;br /&gt;$TableHeader&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;"@&lt;br /&gt;&lt;br /&gt;$rptCollection | ConvertTo-HTML -head $tableStyle –body $body | Out-file $fileName&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-3442274066764528938?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/3442274066764528938/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=3442274066764528938' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3442274066764528938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3442274066764528938'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/11/breadcrumb-auditing-in-exchange-2010.html' title='Breadcrumb auditing in Exchange 2010 with EWS and Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-1715395647616422455</id><published>2010-10-14T09:46:00.002+11:00</published><updated>2010-10-14T10:56:07.712+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Junk Email'/><category scheme='http://www.blogger.com/atom/ns#' term='VBS'/><category scheme='http://www.blogger.com/atom/ns#' term='OWA'/><title type='text'>Making OWA canary's sing using cookies in your OWA scripts</title><content type='html'>In Exchange 2007 SP3 Microsoft implemented canaries in OWA to help prevent man in the middle/cross scripting attacks in OWA &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd458793.aspx#id0080023"&gt;http://msdn.microsoft.com/en-us/magazine/dd458793.aspx#id0080023 &lt;/a&gt;gives a good explanation around why you would want to use a canary and what it is. But put basically a canary is a secret between the client and server in OWA this gets stored in cookie collection of your browser and then it gets submitted with the various requests that your browser sends. If your request doesn't have the canary then the server pretty much says "no OWA for you!". Because in the scripting world it can be useful as a workaround to instrument OWA to automate particular things such as  enabling the extended junk-Email rule in OWA and Outlook in the past I've posted scripts that use &lt;a href="http://gsexdev.blogspot.com/2007/07/turning-on-filter-junk-email-in.html"&gt;OWA automation&lt;/a&gt; that have now pretty much been broken by the canary's. &lt;br /&gt;&lt;br /&gt; So to fix this you need to add some code that will deal with the canary my favorite object to use for these type of scripts is the MSXML2.ServerXMLHTTP object because this handles all the FBA cookies in OWA without the need to add lines of code. To Get the canary from the cookie collection once you have logged on it needs another request to the mailbox your going to access which if things go well means your cookie collection should now be populated and you can just parse the cookie with a few lines of script eg&lt;br /&gt;&lt;br /&gt;req.Open "GET", "https://" &amp;amp; snServername &amp;amp;  "/owa/" &amp;amp; Targetmailbox &amp;amp; "", False&lt;br /&gt;req.SetOption 2, 13056&lt;br /&gt;req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"&lt;br /&gt;req.setRequestHeader "Content-Length", Len(xmlstr)&lt;br /&gt;req.send szXml&lt;br /&gt;reqhedrarry = split(req.GetAllResponseHeaders(), vbCrLf,-1,1)&lt;br /&gt;for each ent in reqhedrarry&lt;br /&gt;    wscript.echo ent&lt;br /&gt;Next&lt;br /&gt;cookie = req.getResponseHeader("Set-Cookie")&lt;br /&gt;if instr(cookie,"=") then&lt;br /&gt;    slen = instr(cookie,"=")+1&lt;br /&gt;    elen = instr(slen,cookie,"&amp;amp;")&lt;br /&gt;    canary = mid(cookie,slen,elen-slen)&lt;br /&gt;    wscript.echo "parsed canary : " &amp;amp; canary&lt;br /&gt;end if&lt;br /&gt;&lt;br /&gt;Once you have the canary you need to make sure you include it in your request for the junkemail script you need to modify the XML sent to look like&lt;br /&gt;&lt;br /&gt;"&amp;lt;params&amp;gt;&amp;lt;canary&amp;gt;" &amp;amp; canary &amp;amp; "&amp;lt;/canary&amp;gt;&amp;lt;fEnbl&amp;gt;1&amp;lt;/fEnbl&amp;gt;&amp;lt;/params&amp;gt;"&lt;br /&gt;&lt;br /&gt; And if everything is good your canary should sing to OWA to and achieve what it is your asking it to do. I've put a updated version of the junkemail script &lt;a href="http://msgdev.mvps.org/exdevblog/owajmail2007v4.zip"&gt;here &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-1715395647616422455?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/1715395647616422455/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=1715395647616422455' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/1715395647616422455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/1715395647616422455'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/10/making-owa-canarys-sing-using-cookies.html' title='Making OWA canary&apos;s sing using cookies in your OWA scripts'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-3334211034755646303</id><published>2010-10-11T08:56:00.009+11:00</published><updated>2010-10-11T16:11:04.484+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Outlook 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Registry'/><title type='text'>Modifying Outlook profiles in Outlook 2010 with VBS and Powershell</title><content type='html'>Outlook profiles can present somewhat of a challenge to any mail administrator regardless of the size of the mail system. One way of looking at Outlook profiles is that they are just a whole collection of registry settings on a machine which is true but the number and compelxity of structures involved means that if you want to write a script that will modify a particular profile for a particular user its not just as simple as modifying a single registry key. In previous versions of Outlook you could generally rely on the GUID "13dbb0c8aa05101a9bb000aa002fc45a" to locate the key where the values for the Exchange settings are located but if you have done any work with Outlook 2010 on windows 7 you will generally find this is nolonger the case and its now more reliable to enumerate all the keys under a particular profile and find a particular setting which will indicate this particular key has the values for the Exchange Setting you want to modify. The one thing that computers are really good at is processing things quickly so if you wanted to for instance modify the cache mode setting within a profile in VBS you could use the following code to locate the default profile&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;Set WshShell = WScript.CreateObject("WScript.Shell")&lt;br /&gt;strComputer = "."&lt;br /&gt;HKEY_CURRENT_USER = &amp;amp;H80000001&lt;br /&gt;Set oReg = GetObject("winmgmts:\\" &amp;amp; strComputer &amp;amp; "\root\default:StdRegProv")&lt;br /&gt;keypath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"&lt;br /&gt;&lt;br /&gt;profile = WshShell.RegRead("HKCU\"&amp;amp;keypath&amp;amp;"DefaultProfile")&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Then enumerate all the keys under this profile to identify the key that has the cache mode value.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;oReg.EnumKey HKEY_CURRENT_USER, (keypath &amp;amp; profile &amp;amp; "\"), arrSubKeys&lt;br /&gt;For Each subkey In arrSubKeys&lt;br /&gt;oReg.EnumValues HKEY_CURRENT_USER, (keypath &amp;amp; profile &amp;amp; "\" &amp;amp; subkey &amp;amp; "\"), arrSubValues&lt;br /&gt;on error resume next&lt;br /&gt;for each ValueKey in arrSubValues&lt;br /&gt;if ValueKey = "00036601" then&lt;br /&gt;oReg.GetBinaryValue HKEY_CURRENT_USER,(keypath &amp;amp; profile &amp;amp; "\" &amp;amp; subkey),"00036601",prProxyValRes&lt;br /&gt;if not IsNull(prProxyValRes) then&lt;br /&gt;if prProxyValRes(0) = "132" then&lt;br /&gt;Wscript.echo "Cache Mode Enabled"&lt;br /&gt;else&lt;br /&gt;Wscript.echo "Cache Mode Disabled"&lt;br /&gt;end if&lt;br /&gt;end if&lt;br /&gt;end if&lt;br /&gt;next&lt;br /&gt;on error goto 0&lt;br /&gt;next&lt;br /&gt;&lt;br /&gt;If you want to change the setting instead of just echoing it out the current setting then you would need to include something like&lt;br /&gt;&lt;br /&gt;newValue1 = Array(&amp;amp;H84,&amp;amp;H05,&amp;amp;H00,&amp;amp;H00)&lt;br /&gt;oReg.SetBinaryValue HKEY_CURRENT_USER,(keypath &amp;amp; profile &amp;amp; "\" &amp;amp; subkey),"00036601",newValue1 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note the hex value that you put in the second array element can vary depending on whether you want to enable the download public folder or shared folders check boxes.&lt;br /&gt;&lt;br /&gt;If you think vbs is for mugs and you want to do this in powershell instead then you would need something like this&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;$RootKey = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"&lt;br /&gt;$pkProfileskey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($RootKey, $true)&lt;br /&gt;$defProf = $pkProfileskey.GetValue("DefaultProfile")&lt;br /&gt;$pkSubProfilekey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey(($RootKey + "\\" + $defProf), $true)&lt;br /&gt;foreach($Valuekey in $pkSubProfilekey.getSubKeyNames()){&lt;br /&gt;$pkSubValueKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey(($RootKey + "\\" + $defProf + "\\" + $Valuekey ), $true)&lt;br /&gt;foreach ($values in $pkSubValueKey.GetValueNames())&lt;br /&gt;{&lt;br /&gt;if ($values -eq "00036601"){&lt;br /&gt;if(($pkSubValueKey.GetValue("00036601"))[0] -eq 132){&lt;br /&gt;"Cache Mode Enabled"}&lt;br /&gt;else{&lt;br /&gt;"Cache Mode Disabled"&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-3334211034755646303?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/3334211034755646303/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=3334211034755646303' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3334211034755646303'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3334211034755646303'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/10/modifying-outlook-profiles-in-outlook.html' title='Modifying Outlook profiles in Outlook 2010 with VBS and Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-2150975503757983781</id><published>2010-09-19T21:04:00.005+10:00</published><updated>2010-09-20T09:02:37.648+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2007'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Recipient \ Email Address Policy GUI and browser for Exchange 2007 / 2010</title><content type='html'>Recipient policies where first introduced in Exchange 2003 and later became email address policies in Exchange 2007 where we where all introduced to the joys and sorrows of Opath. While policies are a simple idea and a good method to do this type of thing the complexities of what happens underneath can be hard to get your head around and test and this can at times lead to the odd mistake. While there is a preview box when your modifying an Address list policy if you wanted to look at the bigger picture of the filter that the address policy represents as it is and could be applied to active directory objects, this is where it can be useful to use a script.  The other thing to take into account when looking a policies is the objects where the application of the address policies have been disabled. So what I've done is build a GUI to help this the first thing this script does is enumerate all the policy objects and retrieve the following properties that are associated with these object.&lt;br /&gt;&lt;br /&gt;GatewayProxy  - This contains the proxyaddresses that will be applied by the policy&lt;br /&gt;&lt;br /&gt;msExchQueryFilter - This is the Opath filter for the policy&lt;br /&gt;&lt;br /&gt;msExchPolicyOrder - This is the priority of the address policy&lt;br /&gt;&lt;br /&gt;msExchPurportedSearchUI - This is a little bit of cheat as this property is used for the UI but it does contain a LDAP filter that can be used directly in ADSI so this is the property that I've used to search active directory for objects that the policy relates to.&lt;br /&gt;&lt;br /&gt;GUID this is stored so it can be compared to the the msexchPoliciesIncluded property to work out if a policy has been applied to a specific object.&lt;br /&gt;&lt;br /&gt;To work out if a policy has been applied to an object and also work out if policies have been disabled two properties are important. If polices have been disabled via the "Automatically update e-mail addresses based on e-mail address policy" then the msExchPoliciesExcluded will be set to 26491CFC-9E50-4857-861B-0CB8DF22B5D7.&lt;br /&gt;&lt;br /&gt;Once a policy has been applied to an AD object the msexchpoliciesincluded will be updated with the GUID of the policy that has been applied. So when it comes time to enumerating applied polices using a script these a properties that you can put to use.&lt;br /&gt;&lt;br /&gt;What happens when you hit the search button is the script does a ADSI query of active directory based on the LDAP filter and will return the objects that match this filter and tell you want policis has been applied to these objects. The radio button let you filter on all object, just the ones where the policy has been applied or disabled.&lt;br /&gt;&lt;br /&gt;Some other things this script can be used for are backing up the current proxyaddress setting of accounts before you make any changes.&lt;br /&gt;&lt;br /&gt;I've put a download of this script &lt;a href="http://msgdev.mvps.org/exdevblog/adprxyguiv2.zip"&gt;here &lt;/a&gt;the script itself looks like&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")&lt;br /&gt;[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")&lt;br /&gt;$form = new-object System.Windows.Forms.form&lt;br /&gt;$raCollection = @()&lt;br /&gt;$usrCollection = @()&lt;br /&gt;$policyhash = @{ }&lt;br /&gt;# $policyhash.Add("26491CFC-9E50-4857-861B-0CB8DF22B5D7","Disabled")&lt;br /&gt;&lt;br /&gt;function UpdateListBoxPolicy(){&lt;br /&gt;   foreach ($prxobj in $raCollection){&lt;br /&gt;      if ($prxobj.PolicyName -eq $policyNameDrop.SelectedItem.ToString()){&lt;br /&gt;           $lbListView.clear()&lt;br /&gt;           $lbListView.Columns.Add("Property",80)&lt;br /&gt;           $lbListView.Columns.Add("Value",220)&lt;br /&gt;           $item1 = new-object System.Windows.Forms.ListViewItem("GUID")&lt;br /&gt;           $item1.SubItems.Add($prxobj.GUID.ToString())&lt;br /&gt;           $lbListView.items.add($item1)&lt;br /&gt;           $item1 = new-object System.Windows.Forms.ListViewItem("OpathFilter")&lt;br /&gt;           $item1.SubItems.Add($prxobj.OpathFilter.ToString())&lt;br /&gt;           $lbListView.items.add($item1)&lt;br /&gt;           $item1 = new-object System.Windows.Forms.ListViewItem("gatewayProxy")&lt;br /&gt;           if ($prxobj.gatewayProxy -is [system.array]){&lt;br /&gt;                $item1.SubItems.Add(([string]::join(";", $prxobj.gatewayProxy)))             &lt;br /&gt;           }&lt;br /&gt;           else{&lt;br /&gt;              $item1.SubItems.Add($prxobj.gatewayProxy.ToString())&lt;br /&gt;           }&lt;br /&gt;           $lbListView.items.add($item1)&lt;br /&gt;           $item1 = new-object System.Windows.Forms.ListViewItem("LDAPFilter")&lt;br /&gt;           $item1.SubItems.Add($prxobj.LDAPFilter.ToString())&lt;br /&gt;           $lbListView.items.add($item1)&lt;br /&gt;           $item1 = new-object System.Windows.Forms.ListViewItem("msExchPolicyOrder")&lt;br /&gt;           $item1.SubItems.Add($prxobj.msExchPolicyOrder.ToString())&lt;br /&gt;           $lbListView.items.add($item1)&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function ExportGrid(){&lt;br /&gt;$exFileName = new-object System.Windows.Forms.saveFileDialog&lt;br /&gt;$exFileName.DefaultExt = "csv"&lt;br /&gt;$exFileName.Filter = "csv files (*.csv)|*.csv"&lt;br /&gt;$exFileName.InitialDirectory = "c:\temp"&lt;br /&gt;$exFileName.ShowHelp = $true&lt;br /&gt;$exFileName.ShowDialog()&lt;br /&gt;if ($exFileName.FileName -ne ""){&lt;br /&gt;   $logfile = new-object IO.StreamWriter($exFileName.FileName,$true)&lt;br /&gt;   $logfile.WriteLine("DisplayName,PrimaryEmailAdrress,ProxyAddresses,RecipientPolicy")&lt;br /&gt;   foreach($row in $msTable.Rows){&lt;br /&gt;       $logfile.WriteLine("`"" + $row[0].ToString() + "`"," + $row[1].ToString() + "," + $row[2].ToString() + "," + $row[3].ToString())&lt;br /&gt;   }&lt;br /&gt;   $logfile.Close()&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function SearchforObjects(){&lt;br /&gt;$policyobject = ""&lt;br /&gt;foreach ($prxobj in $raCollection){&lt;br /&gt;      if ($prxobj.PolicyName -eq $policyNameDrop.SelectedItem.ToString()){&lt;br /&gt;           $policyobject = $prxobj.LDAPFilter.ToString()&lt;br /&gt;      }&lt;br /&gt;}&lt;br /&gt;$msTable.clear()&lt;br /&gt;$dfDefaultRootPath = "LDAP://" + $root.DefaultNamingContext.tostring()&lt;br /&gt;$dfRoot = [ADSI]$dfDefaultRootPath&lt;br /&gt;$gfGALQueryFilter =  $policyobject&lt;br /&gt;$dfsearcher = new-object System.DirectoryServices.DirectorySearcher($dfRoot)&lt;br /&gt;$dfsearcher.Filter = $gfGALQueryFilter&lt;br /&gt;$dfsearcher.PageSize = 1000&lt;br /&gt;$dfsearcher.PropertiesToLoad.Add("msexchPoliciesIncluded")&lt;br /&gt;$dfsearcher.PropertiesToLoad.Add("proxyAddresses")&lt;br /&gt;$dfsearcher.PropertiesToLoad.Add("mail")&lt;br /&gt;$dfsearcher.PropertiesToLoad.Add("displayName")&lt;br /&gt;$dfsearcher.PropertiesToLoad.Add("distinguishedName")&lt;br /&gt;$dfsearcher.PropertiesToLoad.Add("msExchPoliciesExcluded")&lt;br /&gt;$srSearchResult = $dfsearcher.FindAll()&lt;br /&gt;foreach ($emResult in $srSearchResult) {&lt;br /&gt;   $emProps = $emResult.Properties&lt;br /&gt;   $DisplayName = ""&lt;br /&gt;   $PrimaryEmailAdrress = ""&lt;br /&gt;   $ProxyAddresses = ""&lt;br /&gt;   $RecipientPolicy = ""&lt;br /&gt;   if($emProps.msexchpoliciesincluded -ne $null){&lt;br /&gt;       $polarray = $emProps.msexchpoliciesincluded[0].Split(",")&lt;br /&gt;       foreach($pol in $polarray){&lt;br /&gt;           $pol = $pol.ToString().Replace("{","").Replace("}","")&lt;br /&gt;           if ($policyhash.ContainsKey($pol.ToString())){&lt;br /&gt;                     $RecipientPolicy = $policyhash[$pol.ToString()]&lt;br /&gt;                    &lt;br /&gt;            }     &lt;br /&gt;         }&lt;br /&gt;   }&lt;br /&gt;   if ($emProps.msexchpoliciesexcluded -ne $null){&lt;br /&gt;   foreach($pol in $emProps.msexchpoliciesexcluded){&lt;br /&gt;        $pol = $pol.ToString().Replace("{","").Replace("}","")&lt;br /&gt;        $pol.ToString()&lt;br /&gt;        if ($pol.ToString() -eq "26491CFC-9E50-4857-861B-0CB8DF22B5D7"){&lt;br /&gt;                  $RecipientPolicy = "Disabled"&lt;br /&gt;               &lt;br /&gt;        }     &lt;br /&gt;   }&lt;br /&gt;   }&lt;br /&gt;   $DisplayName = $emResult.Properties["displayname"][0]&lt;br /&gt;   $PrimaryEmailAdrress = $emResult.Properties["mail"][0]&lt;br /&gt;   $ProxyAddresses = [string]::join(";",$emProps.proxyaddresses)&lt;br /&gt;   if($rbinc.Checked -eq $true){&lt;br /&gt;       $msTable.rows.add($DisplayName,$PrimaryEmailAdrress,$ProxyAddresses,$RecipientPolicy)&lt;br /&gt;   }&lt;br /&gt;   if($rbinc1.Checked -eq $true -band $RecipientPolicy -eq $policyNameDrop.SelectedItem.ToString()){&lt;br /&gt;       $msTable.rows.add($DisplayName,$PrimaryEmailAdrress,$ProxyAddresses,$RecipientPolicy)&lt;br /&gt;   }&lt;br /&gt;   if($rbinc2.Checked -eq $true -band $RecipientPolicy -eq "Disabled"){&lt;br /&gt;       $msTable.rows.add($DisplayName,$PrimaryEmailAdrress,$ProxyAddresses,$RecipientPolicy)&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;  $dgDataGrid.Datasource = $msTable&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$root = [ADSI]'LDAP://RootDSE'&lt;br /&gt;$cfConfigRootpath = "LDAP://" + $root.ConfigurationNamingContext.tostring()&lt;br /&gt;$configRoot = [ADSI]$cfConfigRootpath&lt;br /&gt;$searcher = new-object System.DirectoryServices.DirectorySearcher($configRoot)&lt;br /&gt;$searcher.Filter = "(objectClass=msexchRecipientPolicy)"&lt;br /&gt;$searchresults = $searcher.FindAll()&lt;br /&gt;foreach ($searchresult in $searchresults){&lt;br /&gt;   $plcobj = "" | select PolicyName,GUID,gatewayProxy,OpathFilter,LDAPFilter,msExchPolicyOrder&lt;br /&gt;   $Policyobject = New-Object System.DirectoryServices.directoryentry&lt;br /&gt;   $Policyobject = $searchresult.GetDirectoryEntry()&lt;br /&gt;   $plcobj.PolicyName = $Policyobject.Name.Value&lt;br /&gt;   $plcobj.GUID = [GUID]$Policyobject.ObjectGUID.Value&lt;br /&gt;   $plcobj.OpathFilter = $Policyobject.msExchQueryFilter.Value&lt;br /&gt;   $plcobj.gatewayProxy = $Policyobject.GatewayProxy.Value&lt;br /&gt;   $plcobj.msExchPolicyOrder = $Policyobject.msExchPolicyOrder.Value&lt;br /&gt;   foreach ($val in $Policyobject.msExchPurportedSearchUI){&lt;br /&gt;       if($val -match "Microsoft.PropertyWell_QueryString="){&lt;br /&gt;           $plcobj.LDAPFilter = $val.substring(35,($val.length-35))&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;   $raCollection += $plcobj&lt;br /&gt;   $policyhash.add($plcobj.GUID.ToString(),$plcobj.PolicyName)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$msTable = New-Object System.Data.DataTable&lt;br /&gt;$msTable.TableName = "ProxyAddress"&lt;br /&gt;$msTable.Columns.Add("DisplayName")&lt;br /&gt;$msTable.Columns.Add("PrimaryEmailAdrress")&lt;br /&gt;$msTable.Columns.Add("ProxyAddresses")&lt;br /&gt;$msTable.Columns.Add("RecipientPolicy")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$PolicylableBox = new-object System.Windows.Forms.Label&lt;br /&gt;$PolicylableBox.Location = new-object System.Drawing.Size(10,20)&lt;br /&gt;$PolicylableBox.size = new-object System.Drawing.Size(120,20)&lt;br /&gt;$PolicylableBox.Text = "Select Policy Name : "&lt;br /&gt;$form.controls.Add($PolicylableBox)&lt;br /&gt;&lt;br /&gt;# Add Policy Drop Down&lt;br /&gt;$policyNameDrop = new-object System.Windows.Forms.ComboBox&lt;br /&gt;$policyNameDrop.Location = new-object System.Drawing.Size(130,20)&lt;br /&gt;$policyNameDrop.Size = new-object System.Drawing.Size(200,30)&lt;br /&gt;$policyNameDrop.Enabled = $true&lt;br /&gt;foreach ($prxobj in $raCollection){&lt;br /&gt;   $policyNameDrop.Items.Add($prxobj.PolicyName)&lt;br /&gt;}&lt;br /&gt;$policyNameDrop.Add_SelectedValueChanged({UpdateListBoxPolicy})&lt;br /&gt;$form.Controls.Add($policyNameDrop)&lt;br /&gt;&lt;br /&gt;$policySettingslableBox = new-object System.Windows.Forms.Label&lt;br /&gt;$policySettingslableBox.Location = new-object System.Drawing.Size(340,20)&lt;br /&gt;$policySettingslableBox.size = new-object System.Drawing.Size(80,20)&lt;br /&gt;$policySettingslableBox.Text = "Policy Settings"&lt;br /&gt;$form.controls.Add($policySettingslableBox)&lt;br /&gt;&lt;br /&gt;$lbListView = new-object System.Windows.Forms.ListView&lt;br /&gt;$lbListView.Location = new-object System.Drawing.Size(450,20)&lt;br /&gt;$lbListView.size = new-object System.Drawing.Size(350,100)&lt;br /&gt;$lbListView.LabelEdit = $True&lt;br /&gt;$lbListView.AllowColumnReorder = $True&lt;br /&gt;$lbListView.CheckBoxes = $False&lt;br /&gt;$lbListView.FullRowSelect = $True&lt;br /&gt;$lbListView.GridLines = $True&lt;br /&gt;$lbListView.View = "Details"&lt;br /&gt;$lbListView.Sorting = "Ascending"&lt;br /&gt;$form.controls.Add($lbListView)&lt;br /&gt;&lt;br /&gt;# Add RadioButtons&lt;br /&gt;$rbinc = new-object System.Windows.Forms.RadioButton&lt;br /&gt;$rbinc.Location = new-object System.Drawing.Size(150,50)&lt;br /&gt;$rbinc.size = new-object System.Drawing.Size(220,17)&lt;br /&gt;$rbinc.Checked = $true&lt;br /&gt;$rbinc.Text = "All objects Policy Query matches"&lt;br /&gt;$form.Controls.Add($rbinc)&lt;br /&gt;&lt;br /&gt;$rbinc1 = new-object System.Windows.Forms.RadioButton&lt;br /&gt;$rbinc1.Location = new-object System.Drawing.Size(150,70)&lt;br /&gt;$rbinc1.size = new-object System.Drawing.Size(220,17)&lt;br /&gt;$rbinc1.Checked = $false&lt;br /&gt;$rbinc1.Text = "Only objects with Apply policy enabled"&lt;br /&gt;$form.Controls.Add($rbinc1)&lt;br /&gt;&lt;br /&gt;$rbinc2 = new-object System.Windows.Forms.RadioButton&lt;br /&gt;$rbinc2.Location = new-object System.Drawing.Size(150,90)&lt;br /&gt;$rbinc2.size = new-object System.Drawing.Size(220,17)&lt;br /&gt;$rbinc2.Checked = $false&lt;br /&gt;$rbinc2.Text = "Only objects with Apply policy disabled"&lt;br /&gt;$form.Controls.Add($rbinc2)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$exButton1 = new-object System.Windows.Forms.Button&lt;br /&gt;$exButton1.Location = new-object System.Drawing.Size(10,70)&lt;br /&gt;$exButton1.Size = new-object System.Drawing.Size(125,20)&lt;br /&gt;$exButton1.Text = "Search"&lt;br /&gt;$exButton1.Add_Click({SearchforObjects})&lt;br /&gt;$form.Controls.Add($exButton1)&lt;br /&gt;&lt;br /&gt;# Add Export Grid Button&lt;br /&gt;&lt;br /&gt;$exButton2 = new-object System.Windows.Forms.Button&lt;br /&gt;$exButton2.Location = new-object System.Drawing.Size(10,760)&lt;br /&gt;$exButton2.Size = new-object System.Drawing.Size(125,20)&lt;br /&gt;$exButton2.Text = "Export Grid"&lt;br /&gt;$exButton2.Add_Click({ExportGrid})&lt;br /&gt;$form.Controls.Add($exButton2)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# Add DataGrid View&lt;br /&gt;&lt;br /&gt;$dgDataGrid = new-object System.windows.forms.DataGridView&lt;br /&gt;$dgDataGrid.Location = new-object System.Drawing.Size(10,145)&lt;br /&gt;$dgDataGrid.size = new-object System.Drawing.Size(1000,600)&lt;br /&gt;$dgDataGrid.AutoSizeRowsMode = "AllHeaders"&lt;br /&gt;$form.Controls.Add($dgDataGrid)&lt;br /&gt;&lt;br /&gt;$form.Text = "Address Policy GUI"&lt;br /&gt;$form.size = new-object System.Drawing.Size(1200,750)&lt;br /&gt;$form.autoscroll = $true&lt;br /&gt;$form.Add_Shown({$form.Activate()})&lt;br /&gt;$form.ShowDialog()&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-2150975503757983781?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/2150975503757983781/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=2150975503757983781' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/2150975503757983781'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/2150975503757983781'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/09/recipient-email-address-policy-gui-and.html' title='Recipient \ Email Address Policy GUI and browser for Exchange 2007 / 2010'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-6396305102134273565</id><published>2010-09-10T11:23:00.003+10:00</published><updated>2010-09-10T12:41:20.422+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2007'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><title type='text'>Cleaning up and Reporting on Items based on the Subject on Exchange using a EWS search with Powershell</title><content type='html'>If your unaware there is nasty mass mailer virus outbreak at the moment if you haven't already i would strongly urge you to visit and implement the measures in &lt;a rel="nofollow" target="_blank" href="http://social.technet.microsoft.com/wiki/contents/articles/worm-win32-visal-b.aspx"&gt;&lt;span class="yshortcuts" id="lw_1284082044_0"&gt;http://social.technet.microsoft.com/wiki/contents/articles/worm-win32-visal-b.aspx&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt; The above gives the best and quickest method for cleaning the affects of an outbreak using the EMS export-mailbox cmdlet but i thought I'd give some alternate methods using EWS . I can't guarantee any of these methods like i would with Export-mailbox and I would expect them to be slower (and possibly very slow) but they may come in use especially if your access is limited but you can use EWS Impersonation or if you looking to do some reporting based on subject.&lt;br /&gt;&lt;br /&gt;  Finding Items based on there Subject is relatively simple in EWS and involves the use of a Search filter or if your lucky enough to be using Exchange 2010 you can make use of AQS which I blogged about earlier &lt;a href="http://gsexdev.blogspot.com/2010/08/using-exchange-search-and-aqs-with-ews.html"&gt;here&lt;/a&gt; . With a virus outbreak they generally start on a particular date so it makes sense to make your query more efficient by only searching for items that where received in the last 7 days. So a search filter for 2007 would look like&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;    $Sfir = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::Subject, $subjecttoSearch)&lt;br /&gt;    $Sflt = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsGreaterThan([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived, $MailDate)&lt;br /&gt;    $sfCollection = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And);&lt;br /&gt;    $sfCollection.add($Sfir)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The AQS query for the same thing would look like AQSQuery = "Received:this week AND subject:`"" + $subjecttoSearch + "`"" . There is one very important catch with the AQS query is that it will do a exact phrase match but not a exact subject match. So for example if you where trying to match the phrase "&lt;span style="font-size:78%;color:maroon;"&gt;&lt;span style="font-size: 9pt; font-family: &amp;quot;Courier New&amp;quot;; color: maroon;"&gt;here you have&lt;/span&gt;&lt;/span&gt;" in the subject it would also match &lt;span style="font-size:78%;color:maroon;"&gt;&lt;span style="font-size: 9pt; font-family: &amp;quot;Courier New&amp;quot;; color: maroon;"&gt;"here you have a example of"&lt;/span&gt;&lt;/span&gt; there are different operators that you can use in AQS but not one that i could find that would do a exact property match(I anybody finds an AQS query that works (emphasis on works rather then should work based on the documentation) please let me know). To get around this and also as a double check before you delete anything a simple logic if statement can be used in your code.&lt;span style="font-size:78%;color:maroon;"&gt;&lt;span style="font-size: 9pt; font-family: &amp;quot;Courier New&amp;quot;; color: maroon;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;When it comes to deleting Items in the EWS Managed API you can use the Delete method of the Item object which would basically call a deleteItem operation each time you called this method or a faster method is create an array of itemid's that you would like deleted and then use the batch deleteItems method which is the method I've used.&lt;br /&gt;&lt;br /&gt;The scripts are setup to use Delegation but if you want to use impersonation instead just add the following line&lt;br /&gt;&lt;br /&gt;&lt;span class="re0"&gt;$service&lt;/span&gt;.ImpersonatedUserId &lt;span class="sy0"&gt;=&lt;/span&gt; &lt;span class="kw1"&gt;New-Object&lt;/span&gt; Microsoft.Exchange.WebServices.Data.ImpersonatedUserId&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;[&lt;/span&gt;Microsoft.Exchange.WebServices.Data.ConnectingIdType&lt;span class="br0"&gt;]&lt;/span&gt;::SmtpAddress&lt;span class="sy0"&gt;,&lt;/span&gt; &lt;span class="re0"&gt;&lt;/span&gt;&lt;span class="br0"&gt;$MailboxName)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Because searching like this is not only usefully for deleting Items but for also reporting on things I've created a reporting version of the scripts as well that just emails a html report of a what it finds within a mailbox and includes the transport headers of the messages in question.  The script I've created does a deep traversal to get the folderid details and then a single finditems on each folder the 2007 version using searchfilters and the 2010 version use AQS.&lt;br /&gt;&lt;br /&gt;The delete scripts do a SoftDelete meaning the item goes into the dumpster of the folder it was deleted from (you could make this a hard delete).&lt;br /&gt;&lt;br /&gt; Before using these script you need to customize the following variable with the subject you want to search for the example I've used is I hate spam&lt;br /&gt;&lt;br /&gt;$subjecttoSearch  = "I hate Spam"&lt;br /&gt;&lt;br /&gt;You also need to set the mailbox name to run against or change it to $arg[0] and run the script with a cmdline argument. In the reporting script the To,From and SMTP server needs to be set.&lt;br /&gt;&lt;br /&gt; I've put a download of all 4 scripts &lt;a href="http://msgdev.mvps.org/exdevblog/cleanandreportews.zip"&gt;here &lt;/a&gt;the 2007 delete version looks like.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;$MailboxName = "user@mailbox.com"&lt;br /&gt;&lt;br /&gt;$subjecttoSearch  = "I hate Spam"&lt;br /&gt;$MailDate = [system.DateTime]::Now.AddDays(-7)&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;&lt;br /&gt;$deleteMode = [Microsoft.Exchange.WebServices.Data.DeleteMode]::SoftDelete&lt;br /&gt;$aptcancelMode = [Microsoft.Exchange.WebServices.Data.SendCancellationsMode]::SendToNone&lt;br /&gt;$taskmode =  [Microsoft.Exchange.WebServices.Data.AffectedTaskOccurrence]::AllOccurrences&lt;br /&gt;&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)&lt;br /&gt;&lt;br /&gt;$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()&lt;br /&gt;$sidbind = "LDAP://&amp;lt;SID=" + $windowsIdentity.user.Value.ToString() + "&amp;gt;"&lt;br /&gt;$aceuser = [ADSI]$sidbind&lt;br /&gt;&lt;br /&gt;$service.AutodiscoverUrl($aceuser.mail.ToString())&lt;br /&gt;&lt;br /&gt;$rfRootFolderID = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$MailboxName)&lt;br /&gt;$rfRootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$rfRootFolderID)&lt;br /&gt;$fvFolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(10000);&lt;br /&gt;$fvFolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep&lt;br /&gt;$fvFolderView.PropertySet = $Propset&lt;br /&gt;$ffResponse = $rfRootFolder.FindFolders($fvFolderView);&lt;br /&gt;&lt;br /&gt;foreach ($ffFolder in $ffResponse.Folders){&lt;br /&gt;    "Checking " + $ffFolder.DisplayName&lt;br /&gt;    $Sfir = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::Subject, $subjecttoSearch)&lt;br /&gt;    $Sflt = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsGreaterThan([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived, $MailDate)&lt;br /&gt;    $sfCollection = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And);&lt;br /&gt;    $sfCollection.add($Sfir)&lt;br /&gt;    $sfCollection.add($Sflt)&lt;br /&gt;    $ivview = new-object Microsoft.Exchange.WebServices.Data.ItemView(20000)&lt;br /&gt;    $frFolderResult = $ffFolder.FindItems($sfCollection,$ivview)&lt;br /&gt;    $Itembatch = [activator]::createinstance(([type]'System.Collections.Generic.List`1').makegenerictype([Microsoft.Exchange.WebServices.Data.ItemId]))&lt;br /&gt;    foreach ($miMailItems in $frFolderResult.Items){&lt;br /&gt;        if ($miMailItems.Subject -eq $subjecttoSearch){&lt;br /&gt;            "****** Found" + $miMailItems.Subject&lt;br /&gt;            $Itembatch.add($miMailItems.Id)&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    "Number of Items found in folder : " + $Itembatch.Count&lt;br /&gt;    if($Itembatch.Count -ne 0){&lt;br /&gt;        "Deleting " + $Itembatch.Count + " Items"&lt;br /&gt;        $DelResponse = $service.DeleteItems($Itembatch,$deleteMode,$aptcancelMode,$taskmode)&lt;br /&gt;        foreach ($dr in $DelResponse) {&lt;br /&gt;                  $dr.Result&lt;br /&gt;        }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;color:maroon;"&gt;&lt;span style="font-size: 9pt; font-family: &amp;quot;Courier New&amp;quot;; color: maroon;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a rel="nofollow" target="_blank" href="http://social.technet.microsoft.com/wiki/contents/articles/worm-win32-visal-b.aspx"&gt;&lt;span class="yshortcuts" id="lw_1284082044_0"&gt;&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-6396305102134273565?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/6396305102134273565/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=6396305102134273565' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6396305102134273565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6396305102134273565'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/09/cleaning-up-and-reporting-on-items.html' title='Cleaning up and Reporting on Items based on the Subject on Exchange using a EWS search with Powershell'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-6376396820554864614</id><published>2010-09-09T22:13:00.004+10:00</published><updated>2010-09-09T22:51:44.314+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2007'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Getting the Folder Size of a folder using EWS</title><content type='html'>One of the things missing from the standard folder properties when you use EWS to access a mailbox or public folder is the size of the folder. Those that have used other API's to do mailbox and public folder size reporting should already know about the extended mapi property PR_Extended_Message_Size this is what you also need to use in EWS to get the folder size to define this in C# you can use&lt;br /&gt;&lt;br /&gt;            &lt;span style="font-size:78%;"&gt;ExtendedPropertyDefinition PR_Extended_Message_Size = new ExtendedPropertyDefinition(3592, MapiPropertyType.Long);&lt;br /&gt;            PropertySet psPropertySet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_Extended_Message_Size  };&lt;br /&gt;            Folder Inbox = Folder.Bind(service, WellKnownFolderName.Inbox, psPropertySet);&lt;br /&gt;            Object FolderSize = null;&lt;br /&gt;            if (Inbox.TryGetProperty(PR_Extended_Message_Size, out FolderSize)) {&lt;br /&gt;                Console.WriteLine(FolderSize);&lt;br /&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can also make use of this in a script if you want an alternative to Get-MailboxFolderStatistics eg if you wanted to show the size of ever folder in a mailbox you can use the following script I've put a download of this &lt;a href="http://msgdev.mvps.org/exdevblog/fsizev2.zip"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;$MailboxName = "user@domain.com"&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)&lt;br /&gt;&lt;br /&gt;$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()&lt;br /&gt;$sidbind = "LDAP://&lt;sid="&gt;"&lt;br /&gt;$aceuser = [ADSI]$sidbind&lt;br /&gt;&lt;br /&gt;$service.AutodiscoverUrl($aceuser.mail.ToString())&lt;br /&gt;&lt;br /&gt;$rfRootFolderID = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$MailboxName)&lt;br /&gt;$rfRootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$rfRootFolderID)&lt;br /&gt;$fvFolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(10000);&lt;br /&gt;$PR_MESSAGE_SIZE_EXTENDED = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3592, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer)&lt;br /&gt;$Propset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)&lt;br /&gt;$Propset.add($PR_MESSAGE_SIZE_EXTENDED)&lt;br /&gt;$fvFolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep&lt;br /&gt;$fvFolderView.PropertySet = $Propset&lt;br /&gt;$ffResponse = $rfRootFolder.FindFolders($fvFolderView);&lt;br /&gt;&lt;br /&gt;foreach ($ffFolder in $ffResponse.Folders){&lt;br /&gt;    $fldObject = "" | select FolderName,FolderSize&lt;br /&gt;    $folderSize = $null&lt;br /&gt;    $ptProptest2 = $ffFolder.TryGetProperty($PR_MESSAGE_SIZE_EXTENDED, [ref]$folderSize)&lt;br /&gt;    $fldObject.FolderName = $ffFolder.DisplayName&lt;br /&gt;    $fldObject.FolderSize = [INT]$folderSize&lt;br /&gt;    $ReportingCollection += $fldObject    &lt;br /&gt;}&lt;br /&gt;$ReportingCollection   &lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-6376396820554864614?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/6376396820554864614/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=6376396820554864614' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6376396820554864614'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/6376396820554864614'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/09/getting-folder-size-of-folder-using-ews.html' title='Getting the Folder Size of a folder using EWS'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-3605755825038109600</id><published>2010-08-30T20:22:00.003+10:00</published><updated>2010-08-30T21:50:31.729+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EWS Managed API'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange 2007'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange Web Services'/><title type='text'>Reporting on deleted retained items with EWS on Exchange 2007</title><content type='html'>On Exchange servers pre Exchange 2010 when someone deletes an Item in Exchange it goes via the dumpster 1.0. Which is explained in &lt;a href="http://msexchangeteam.com/archive/2009/09/25/452632.aspx"&gt;http://msexchangeteam.com/archive/2009/09/25/452632.aspx&lt;/a&gt; as &lt;span style="font-style: italic;"&gt;"&lt;/span&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;essentially a view stored per folder.  Items in the  dumpster (henceforth known as Dumpster 1.0) stay in the folder where  they were soft-deleted (shift-delete or delete from Deleted Items) and  are stamped with the ptagDeletedOnFlag flag.&lt;/span&gt;&lt;span style="font-style: italic;"&gt;"&lt;/span&gt;  . Being able to report on the items that are stored in these views can be useful for a number of auditing and admin reasons. With Exchange Web Services you query the items stored in these views using a SoftDeleted traversal of the folder in question. This works well for items that are stored in the dumpster of a normal mailbox folder but there is a problem when you have a hierarchy of folders that gets deleted. When this happens you can only query the first of the deleted hierarchy using a soft deleted traversal  and the findfolders operation.  While this is a little disappointing what you can do is still useful and worth putting to use.  The following script makes use of this by going through ever folder in a mailbox and use the following properties to determine if more investigation is needed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;ptagDeletedOnFlag &lt;/span&gt;which details when a Item was deleted&lt;br /&gt;&lt;br /&gt;PR_DELETED_MSG_COUNT which is the count of the delete Items with the dumpster view.&lt;br /&gt;&lt;br /&gt;PR_DELETED_MESSAGE_SIZE_EXTENDED is the size of the Items in the dumpster view.&lt;br /&gt;&lt;br /&gt;Using these properties when going through the folder hierarchy you can tell which folders currently have items of interest in the deleted Items view and is something that you should run a softdeleted traversal on. That's it the rest of the script uses some objects and html to email a report of the mailbox you run it against.&lt;br /&gt;&lt;br /&gt;To use this script you need to have delegate access to the mailbox your reporting on or configure the script to use EWS Impersonation.  The script has a few variables that need to be configured&lt;br /&gt;&lt;br /&gt;$MailboxName = "mailbox@domain.com" Mailbox you want to audit&lt;br /&gt;&lt;br /&gt;and&lt;br /&gt;&lt;br /&gt;$sendAlertTo = "sendto@domain.com"&lt;br /&gt;$sendAlertFrom = "report@domain.com"&lt;br /&gt;$SMTPServer = "smtpservername"&lt;br /&gt;&lt;br /&gt; I've put a download of this script &lt;a href="http://msgdev.mvps.org/exdevblog/ddiveews.zip"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;&lt;br /&gt;$MailboxName = "mailbox@domain.com"&lt;br /&gt;&lt;br /&gt;$sendAlertTo = "sendto@domain.com"&lt;br /&gt;$sendAlertFrom = "report@domain.com"&lt;br /&gt;$SMTPServer = "smtpservername"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll"&lt;br /&gt;[void][Reflection.Assembly]::LoadFile($dllpath)&lt;br /&gt;&lt;br /&gt;$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)&lt;br /&gt;&lt;br /&gt;$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()&lt;br /&gt;$sidbind = "LDAP://&amp;lt;SID=" + $windowsIdentity.user.Value.ToString() + "&amp;gt;"&lt;br /&gt;$aceuser = [ADSI]$sidbind&lt;br /&gt;&lt;br /&gt;$service.AutodiscoverUrl($aceuser.mail.ToString())&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$rptCollection = @()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;## Define Extended Properties&lt;br /&gt;&lt;br /&gt;$PR_DELETED_ON = new-object  Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26255, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::SystemTime)&lt;br /&gt;$PR_DELETED_MSG_COUNT = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26176, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer)&lt;br /&gt;$PR_DELETED_MESSAGE_SIZE_EXTENDED = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26267, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Long)&lt;br /&gt;$PR_DELETED_FOLDER_COUNT = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26177, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer)&lt;br /&gt;$PR_Sender_Name = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(26177, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)&lt;br /&gt;&lt;br /&gt;## End Define Extended Properties&lt;br /&gt;## Define Property Sets&lt;br /&gt;## Folder Set&lt;br /&gt;&lt;br /&gt;$fpsFolderPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)&lt;br /&gt;$fpsFolderPropertySet.add($PR_DELETED_ON)&lt;br /&gt;$fpsFolderPropertySet.add($PR_DELETED_MSG_COUNT)&lt;br /&gt;$fpsFolderPropertySet.add($PR_DELETED_MESSAGE_SIZE_EXTENDED)&lt;br /&gt;$fpsFolderPropertySet.add($PR_DELETED_FOLDER_COUNT)&lt;br /&gt;&lt;br /&gt;## Item Set&lt;br /&gt;&lt;br /&gt;$ipsItemPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly)&lt;br /&gt;$ipsItemPropertySet.add($PR_DELETED_ON)&lt;br /&gt;$ipsItemPropertySet.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::Size)&lt;br /&gt;$ipsItemPropertySet.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject)&lt;br /&gt;$ipsItemPropertySet.Add([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::From)&lt;br /&gt;# End Set&lt;br /&gt;&lt;br /&gt;$rfRootFolderID = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$MailboxName)&lt;br /&gt;$rfRootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$rfRootFolderID)&lt;br /&gt;$fvFolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(10000);&lt;br /&gt;$fvFolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep&lt;br /&gt;$fvFolderView.PropertySet = $fpsFolderPropertySet&lt;br /&gt;# $service.traceenabled = $true&lt;br /&gt;$ffResponse = $rfRootFolder.FindFolders($fvFolderView);&lt;br /&gt;foreach ($ffFolder in $ffResponse.Folders){&lt;br /&gt;    $dcDeleteItemCount = $null&lt;br /&gt;    $fptProptest = $ffFolder.TryGetProperty($PR_DELETED_MSG_COUNT, [ref]$dcDeleteItemCount)&lt;br /&gt;    if($fptProptest){&lt;br /&gt;        if ($dcDeleteItemCount -ne 0){&lt;br /&gt;            $ffFolder.DisplayName +  " - Number Items Deleted :" + $dcDeleteItemCount&lt;br /&gt;            $bcBatchCount = 0;&lt;br /&gt;            $bcBatchSize = 1000&lt;br /&gt;            $ivItemView = new-object Microsoft.Exchange.WebServices.Data.ItemView($bcBatchSize, $bcBatchCount)&lt;br /&gt;            $ivItemView.Traversal = [Microsoft.Exchange.WebServices.Data.ItemTraversal]::SoftDeleted&lt;br /&gt;            $ivItemView.PropertySet = $ipsItemPropertySet&lt;br /&gt;            $service.traceenabled = $false&lt;br /&gt;            while (($fiFindItems = $ffFolder.FindItems($ivItemView)).Items.Count -gt 0)&lt;br /&gt;            {&lt;br /&gt;                foreach ($item in $fiFindItems.Items)&lt;br /&gt;                {&lt;br /&gt;                    $lnum ++&lt;br /&gt;                    write-progress "Processing message" $lnum&lt;br /&gt;                    $delon = $null&lt;br /&gt;                    $ptProptest = $item.TryGetProperty($PR_DELETED_ON, [ref]$delon)&lt;br /&gt;                    $Itemobj = "" | select Type,DeletedOn,From,Subject,Size&lt;br /&gt;                    $Itemobj.DeletedOn = $delon&lt;br /&gt;                    $Itemobj.From = $item.From.Name&lt;br /&gt;                    $Itemobj.Subject = $item.Subject&lt;br /&gt;                    $Itemobj.Size = $item.Size&lt;br /&gt;                    $Itemobj.Type = "Item"&lt;br /&gt;                    $rptCollection += $Itemobj&lt;br /&gt;                }&lt;br /&gt;                $bcBatchCount += $fiFindItems.Items.Count&lt;br /&gt;                $ivItemView = new-object Microsoft.Exchange.WebServices.Data.ItemView($bcBatchSize, $bcBatchCount)&lt;br /&gt;                $ivItemView.Traversal = [Microsoft.Exchange.WebServices.Data.ItemTraversal]::SoftDeleted&lt;br /&gt;                $ivItemView.PropertySet = $ipsItemPropertySet&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    $dcDeletedFolderCount = $null&lt;br /&gt;    $fptProptest = $ffFolder.TryGetProperty($PR_DELETED_FOLDER_COUNT, [ref]$dcDeletedFolderCount)&lt;br /&gt;    if($fptProptest){&lt;br /&gt;        if ($dcDeletedFolderCount -ne 0){&lt;br /&gt;            $ffFolder.DisplayName + " - Number folders Deleted :" + $dcDeletedFolderCount       &lt;br /&gt;            $fvFolderView1 = New-Object Microsoft.Exchange.WebServices.Data.FolderView(10000);&lt;br /&gt;            $fvFolderView1.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::SoftDeleted&lt;br /&gt;            $fvFolderView1.PropertySet = $fpsFolderPropertySet&lt;br /&gt;            $ffResponse2 = $ffFolder.FindFolders($fvFolderView1)&lt;br /&gt;           &lt;br /&gt;            foreach ($ffDelFolder in $ffResponse2.Folders){&lt;br /&gt;                $dcDeletedSize = $null&lt;br /&gt;                $fptProptest = $ffDelFolder.TryGetProperty($PR_DELETED_MESSAGE_SIZE_EXTENDED, [ref]$dcDeletedSize)&lt;br /&gt;                $Deletedon = $null&lt;br /&gt;                $ptProptest = $ffDelFolder.TryGetProperty($PR_DELETED_ON, [ref]$Deletedon)&lt;br /&gt;                $Itemobj = "" | select Type,DeletedOn,From,Subject,Size&lt;br /&gt;                $Itemobj.DeletedOn = $Deletedon&lt;br /&gt;                $Itemobj.Subject = $ffDelFolder.DisplayName&lt;br /&gt;                $Itemobj.Size = $dcDeletedSize&lt;br /&gt;                $Itemobj.Type = "Folder"&lt;br /&gt;                $rptCollection += $Itemobj&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$tableStyle = @"&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;BODY{background-color:white;}&lt;br /&gt;TABLE{border-width: 1px;&lt;br /&gt;  border-style: solid;&lt;br /&gt;  border-color: black;&lt;br /&gt;  border-collapse: collapse;&lt;br /&gt;}&lt;br /&gt;TH{border-width: 1px;&lt;br /&gt;  padding: 10px;&lt;br /&gt;  border-style: solid;&lt;br /&gt;  border-color: black;&lt;br /&gt;  background-color:#66CCCC&lt;br /&gt;}&lt;br /&gt;TD{border-width: 1px;&lt;br /&gt;  padding: 2px;&lt;br /&gt;  border-style: solid;&lt;br /&gt;  border-color: black;&lt;br /&gt;  background-color:white&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;"@&lt;br /&gt; &lt;br /&gt;$body = @"&lt;br /&gt;&amp;lt;p style="font-size:25px;family:calibri;color:#ff9100"&amp;gt;&lt;br /&gt;$TableHeader&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;"@&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$SmtpClient = new-object system.net.mail.smtpClient&lt;br /&gt;$SmtpClient.host =  $SMTPServer&lt;br /&gt;$MailMessage = new-object System.Net.Mail.MailMessage&lt;br /&gt;$MailMessage.To.Add($sendAlertTo)&lt;br /&gt;$MailMessage.From = $sendAlertFrom&lt;br /&gt;$MailMessage.Subject = "Dumpster Report for " +  $MailboxName&lt;br /&gt;$MailMessage.IsBodyHtml = $TRUE&lt;br /&gt;$MailMessage.body = $rptCollection | ConvertTo-HTML -head $tableStyle –body $body&lt;br /&gt;$SMTPClient.Send($MailMessage)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7123450-3605755825038109600?l=gsexdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gsexdev.blogspot.com/feeds/3605755825038109600/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7123450&amp;postID=3605755825038109600' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3605755825038109600'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7123450/posts/default/3605755825038109600'/><link rel='alternate' type='text/html' href='http://gsexdev.blogspot.com/2010/08/reporting-on-deleted-retained-items.html' title='Reporting on deleted retained items with EWS on Exchange 2007'/><author><name>Glen</name><uri>http://www.blogger.com/profile/07323836178158839483</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7123450.post-4317844978174806624</id><published>2010-08-20T16:25:00.007+10:00</published><updated>2010-08-20T20:41:32.361+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='archive'/><category scheme='http://www.blogger.com/atom/ns#' term='PST'/><category scheme='http://www.blogger.com/atom/ns#' term='Powershell'/><category scheme='http://www.blogger.com/atom/ns#' term='Exchange'/><title type='text'>Anaylising the content of a PST file and reporting on the age and type of content using Powershell and WPF</title><content type='html'>As time passes we all receive more and more email, this is one of the irrefutable facts of life for any mail system or anybody with a mailbox. Even the most fastidious of deleters still can't avoid this so at some point in the future you may need to consider achieving.  The fact is your users maybe already self archiving using PST files which like self medicating can lead to serious problems down the track when their laptop goes under a bus.  Exchange 2010 introduced native achieving and SP1 when its released will build on these capabilities, for other versions of exchange there are a bunch of other fine products you can look at to do this. If your looking to ingest PST's into an online archive you may want to first review what content your going to be importing and look at things like how many attachments and what type are they and how old is the content to give you a feel for what your going to be storing and potentially having to backup.&lt;br /&gt;&lt;br /&gt;What this boils down to is if you want to include attachment reporting then you will need a script that will do a pass on every item within a mailbox. This means in real terms that this script is going to be slow to very slow to run on a very large PST file. If you can wait you can get some useful information so there is a trade off their somewhere.&lt;br /&gt;&lt;br /&gt;To loop through every message within a PST file using powershell is pretty easy if you use &lt;span style="font-size:85%;"&gt;Dmitry&lt;/span&gt;'s redemption library &lt;a href="http://www.dimastr.com/redemption/"&gt;http://www.dimastr.com/redemption/&lt;/a&gt;. RDO gives us an easy to use wrapper around exMapi and the Outlooks PST provider. So now we have the ability to go through every item in a pst file the next thing to decide is how you want to group and classify each item. I've chosen to do this by date and content age this gives the most flexibility when it comes to aggregating the data later on. To add extra functionality in this script I've created separate hash's for attachment sizes and types this is something that you can build on yourself all you need to do is think about what it is you want to report and aggregate and then just add in a few lines of your own code.&lt;br /&gt;&lt;br /&gt;When it comes time to report on the data that was collected in the PST sweep this is when Powershell comes into its own with the Group-Object and Measure-Object cmdlets. Because during the sweep i classified each message group depending on the age of the content i can then further re-aggregate this data using some pipeline magic eg&lt;br /&gt;$Datehash.Values | group-object {$_.Folder} | Sort-Object @{expression={(($_.Group | Measure-Object SizeofItems -sum).sum/1MB)}} -Descending | foreach-object{&lt;br /&gt;&lt;br /&gt;  $Charthash2["1 to 3 years"] = $Charthash2["1 to 3 years"] + ($_.Group | Where-Object {$_.ContentAge -eq 36} | Measure-Object SizeofItems -sum).sum/1MB&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;Actually explaining what this line does would take a separate post but when it comes to quantifying numerical information without using a database this is extremely useful. In real words it first groups the data by Folder Name and then allows me to aggregate within the grouped data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Displaying the result&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I decided to try something new with this script instead of using the normal winform GUI I've used a lot in the past i went down the WPF path. WPF (Windows Presentation Framework) first appeared in .NET 3.0 so to use this script you must have the .NET 3.5 framework installed as well as the &lt;a href="http://wpf.codeplex.com/releases/view/40535"&gt;wpftoolkit &lt;/a&gt;which contains both datagrid and chart control I've used in this script.  As far as a comparison between Winforms and WPF from powershell WPF is by far easier to use when building a GUI script because you define all the element in XML then just manipulate the data providers with code. You can use something like Visual studio to build the graphical look for your GUI and then cut and past the code more or less straight into your script with a few small changes. The result of what you get is also visually more pleasing eg these are a few of the screen-shots from this script.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_a4Go8x--KMQ/TG4_oGQzy2I/AAAAAAAAACM/qDwg5o63T6M/s1600/screen1.PNG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 160px;" src="http://4.bp.blogspot.com/_a4Go8x--KMQ/TG4_oGQzy2I/AAAAAAAAACM/qDwg5o63T6M/s320/screen1.PNG" alt="" id="BLOGGER_PHOTO_ID_5507409352429128546" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_a4Go8x--KMQ/TG4_-7oJR1I/AAAAAAAAACU/kJKY8Mx8uBc/s1600/screen2.PNG"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 165px;" src="http://1.bp.blogspot.com/_a4Go8x--KMQ/TG4_-7oJR1I/AAAAAAAAACU/kJKY8Mx8uBc/s320/screen2.PNG" alt="" id="BLOGGER_PHOTO_ID_5507409744711206738" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Using this script&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are a few pre-requisites for using this script first you need redemption &lt;a href="http://www.dimastr.com/redemption/download.htm"&gt;http://www.dimastr.com/redemption/download.htm&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you want to run this on Windows 7 64bit I found i had to use the following launcher script to start a 32bit session to run the script&lt;br /&gt;&lt;br /&gt;&amp;amp;$env:windir\syswow64\windowspowershell\v1.0\powershell.exe -noninteractive -STA&lt;br /&gt;&lt;br /&gt;This also ensures that you have a STA session of powershell which is important for the WPF code to work correctly. The last things that's required is the WPFtoolkit which you can downloaded from &lt;a href="http://wpf.codeplex.com/releases/view/40535"&gt;http://wpf.codeplex.com/releases/view/40535&lt;/a&gt;. Note if this gets installed to anywhere other then C:\Program Files (x86)\WPF Toolkit" + "\v3.5.50211.1\ you will need to change the path.&lt;br /&gt;&lt;br /&gt; To run the script you need to pass it the path to the PST file as a cmdline argument eg ./pstanlv1.ps1 "c:\mail\outlook.pst"&lt;br /&gt;&lt;br /&gt; I've put a download of this script &lt;a href="http://msgdev.mvps.org/exdevblog/pstanlv1.zip"&gt;here &lt;/a&gt;the code itself looks like&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;$fnFileName = $args[0]&lt;br /&gt;&lt;br /&gt;$Datehash = new-object "System.Collections.Generic.Dictionary[System.string, System.object]"&lt;br /&gt;$AttachmentTypehash  = @{ }&lt;br /&gt;$ItemTypehash = @{ }&lt;br /&gt;Add-Type -Assembly PresentationFramework&lt;br /&gt;$dataVisualization = "C:\Program Files (x86)\WPF Toolkit" + "\v3.5.50211.1\System.Windows.Controls.DataVisualization.Toolkit.dll"&lt;br /&gt;$wpfToolkit = "C:\Program Files (x86)\WPF Toolkit" + "\v3.5.50211.1\WPFToolkit.dll"&lt;br /&gt;Add-Type -Path $dataVisualization&lt;br /&gt;Add-Type -Path $wpfToolkit&lt;br /&gt;&lt;br /&gt;[xml]$xaml = @"&lt;br /&gt;&amp;lt;Window&lt;br /&gt;        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;br /&gt;        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&lt;br /&gt;        xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"&lt;br /&gt;    xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"&lt;br /&gt;        Title="MainWindow" Height="auto" Width="auto"&amp;gt;&lt;br /&gt;&amp;lt;Grid&amp;gt;&lt;br /&gt;&amp;lt;TabControl Height="auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,0" Name="Home" Width="auto"&amp;gt;&lt;br /&gt;   &amp;lt;TabItem Header="OverView" Name="OverView"&amp;gt;&lt;br /&gt;        &amp;lt;Grid&amp;gt;&lt;br /&gt;    &amp;lt;Canvas Height="Auto" HorizontalAlignment="Left" Margin="0,0,0,0" Name="canvas1" VerticalAlignment="Top" Width="Auto"&amp;gt;&amp;lt;/Canvas&amp;gt;&lt;br /&gt;    &amp;lt;dg:DataGrid AutoGenerateColumns="True" Height="Auto" HorizontalAlignment="Left" Margin="0,0,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="600" /&amp;gt;&lt;br /&gt;        &amp;lt;chartingToolkit:Chart x:Name="PieChart1"  Margin="600,0,0,250"&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:Chart.Series&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:PieSeries ItemsSource="{Binding}"&lt;br /&gt;    DependentValuePath="Value"&lt;br /&gt;    IndependentValuePath="Key" /&amp;gt;&lt;br /&gt;    &amp;lt;/chartingToolkit:Chart.Series&amp;gt;&lt;br /&gt;    &amp;lt;/chartingToolkit:Chart&amp;gt;&lt;br /&gt;        &amp;lt;chartingToolkit:Chart x:Name="PieChart2"  Margin="600,250,0,00"&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:Chart.Series&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:PieSeries ItemsSource="{Binding}"&lt;br /&gt;    DependentValuePath="Value.SizeofAttachments"&lt;br /&gt;    IndependentValuePath="Key" /&amp;gt;&lt;br /&gt;    &amp;lt;/chartingToolkit:Chart.Series&amp;gt;&lt;br /&gt;    &amp;lt;/chartingToolkit:Chart&amp;gt;&lt;br /&gt;      &amp;lt;/Grid&amp;gt;&lt;br /&gt;     &amp;lt;/TabItem&amp;gt;&lt;br /&gt;     &amp;lt;TabItem Header="Content Age" Name="Cage"&amp;gt;&lt;br /&gt;        &amp;lt;Grid&amp;gt;&lt;br /&gt;       &amp;lt;Canvas Height="Auto" HorizontalAlignment="Left" Margin="0,0,0,0" Name="canvas2" VerticalAlignment="Top" Width="Auto"&amp;gt;&amp;lt;/Canvas&amp;gt;&lt;br /&gt;       &amp;lt;DataGrid AutoGenerateColumns="True" Height="Auto" HorizontalAlignment="Left" Margin="0,250,0,0" Name="dataGrid2" VerticalAlignment="Top" Width="auto" /&amp;gt;&lt;br /&gt;        &amp;lt;chartingToolkit:Chart x:Name="PieChart3"  Margin="0,0,0,250"&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:Chart.Series&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:PieSeries ItemsSource="{Binding}"&lt;br /&gt;    DependentValuePath="Value"&lt;br /&gt;    IndependentValuePath="Key" /&amp;gt;&lt;br /&gt;    &amp;lt;/chartingToolkit:Chart.Series&amp;gt;&lt;br /&gt;    &amp;lt;/chartingToolkit:Chart&amp;gt;&lt;br /&gt;       &amp;lt;/Grid&amp;gt;&lt;br /&gt;     &amp;lt;/TabItem&amp;gt;&lt;br /&gt;     &amp;lt;TabItem Header="Item Type" Name="Itype"&amp;gt;&lt;br /&gt;        &amp;lt;Grid&amp;gt;&lt;br /&gt;    &amp;lt;Canvas Height="Auto" HorizontalAlignment="Left" Margin="0,0,0,0" Name="canvas3" VerticalAlignment="Top" Width="Auto"&amp;gt;&amp;lt;/Canvas&amp;gt;&lt;br /&gt;    &amp;lt;dg:DataGrid AutoGenerateColumns="True" Height="Auto" HorizontalAlignment="Left" Margin="0,0,0,0" Name="dataGrid3" VerticalAlignment="Top" Width="400" /&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:Chart x:Name="PieChart4"  Margin="400,0,0,250"  Title="Item type by Item Count"&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:Chart.Series&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:PieSeries ItemsSource="{Binding}"&lt;br /&gt;    DependentValuePath="Value.NumberofItems"&lt;br /&gt;    IndependentValuePath="Key" /&amp;gt;&lt;br /&gt;    &amp;lt;/chartingToolkit:Chart.Series&amp;gt;&lt;br /&gt;    &amp;lt;/chartingToolkit:Chart&amp;gt;&lt;br /&gt;        &amp;lt;chartingToolkit:Chart x:Name="PieChart5"  Margin="400,250,0,00" Title="Item type by Item Size"&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:Chart.Series&amp;gt;&lt;br /&gt;    &amp;lt;chartingToolkit:PieSeries ItemsSource="{Binding}"&lt;br /&gt;    DependentValuePath="Value.SizeofItems"&lt;br /&gt;    IndependentValuePath="Key" /&amp;gt;&lt;br /&gt;    &amp;lt;/chartingToolkit:Chart.Series&amp;gt;&lt;br /&gt;    &amp;lt;/chartingToolkit:Chart&amp;gt;&lt;br /&gt
