Skip to main content

Posts

Forwarding a Message as an Attachment using the EWS Managed API and Powershell

While you can easily create an Inbox rule to forward a Message as an Attachment, doing this programmatically in EWS isn't that straight forward. As there is no direct method in EWS to attach an existing Store item a work around is needed. With this workaround we use the MimeContent of an existing email message which will allow you to create an ItemAttachment of this existing message (using the method from this post) in the Inbox and maintain all the Mime Properties and attachments on the message your forwarding. Note this method doesn't maintain full fidelity of a Message as it won't include any MAPI properties or Exchange rich datatypes which may or may not be important. The following sample demonstrates how to forward the more recently received email in the Inbox as an Item Attachment using the MimeContent (and also setting the MessageFlags property to make sure the message appears sent).  $folderid=  new -object Microsoft.Exchange.WebServices.Data.FolderId([Mic...

Creating Item Attachments with the EWS Managed API with Powershell

Item Attachments in EWS allow you to create an Attachment that is of a Rich Exchange type such as an EmailMessage, Task, Post, Contact etc or even your own custom form if your using these. Although one thing you can't do with an Item attachment is attach an existing Exchange Item. To use ItemAttachments in Powershell you need to use reflection in .NET as it involves invoking a Generic Method which is not that straight forward in Powershell. The following is an example of creating a Task as an Item Attachment in Powershell using reflection $mail  =  New-Object  Microsoft.Exchange.WebServices.Data.EmailMessage( $service );   $AtColtype  = ( "Microsoft.Exchange.WebServices.Data.AttachmentCollection" ) -as  "Type"    $Tasktype  = ( "Microsoft.Exchange.WebServices.Data.Task" ) -as  "Type"    $methodInf  =  $AtColtype .GetMethod( "AddItemAttachment" );   $AddItmAttachMeth...

EWS Powershell default Mailbox Folder ACE audit script

The default Access Control Entry ACE in an Exchange Mailbox Folder DACL controls the rights that all authenticated users have to a particularity mailbox folder. Generally from a security perspective its something you don't want users to use as they may not understand when then set this ACE they are giving all people access to certain information. Eg Giving the default user reviewer rights to your Inbox means everyone in the Exchange org can now read mailbox in you Inbox which may not provide much privacy to your email. The following script will enumerate the permissions on every folder in a Mailbox and then produce a report of the folders where the default ACE isn't set to none. For most users the only folder that should show up in the report in the calendar folder. This script uses EWS but you could also use the Exchange Management Shell Get-MailboxFolderPermission cmdlet. To run this script you need to feed is with a CSV file that contains the SMTPAddress of the Mailboxes y...

EWS Findpeople workaround for reading the Offline Address Book in Office365 / Exchange Online

A couple of weeks ago I posted this about using the new FindPeople operation in EWS with Exchange 2013 to enumerate through the Global Address List. As I mentioned one pain point around using this new operation on Office365 is that you need to know the AddressList Id which there is no way of dynamically getting via EWS. This has been bugging me for a while so I started thinking about some ways of working around this and one method I found that did work is you can obtain the Id for the Offline Address Book and then query this (which is mostly as good as querying the Online GAL). To Get the Id of the Offline Address book what you first need to do is use AutoDiscover to get the External OAB url, Then use a normal Get request on this url for the oab.xml file. Then you can parse from the OAB.xml file the Guid value of the OAB which you can transform into an AddressList id that you can then use with EWS to query the OAB. The following C# sample use the EWS Managed API for Autodiscover and...

EWS/Powershell Recoverable Items age report for Exchange 2010/13

With Single Item Recovery in Exchange 2010 and Exchange 2013, the Recoverable Items Folder in an Exchange Mailbox becomes one of the things you may want to pay some more special attention to in the course of managing the disk resource that are being consumed within your Exchange Org. The following is a script that does another take on ItemAge reporting by basically crawling every item in a folder and then grouping the DateTimeRecieved (to get the age of the Item) and the ModifiedTime(which is when its deleted). The script produces a report like the following for the Mailbox you run it against To use the script you just need to enter the SMTPAddress of the Mailbox you want to run it against and as long as you have rights to the mailbox you should get a report. I've put a download of the script here the code looks like ## Get the Mailbox to Access from the 1st commandline argument       $MailboxName ...

Using the EWS FindPeople operation in Exchange 2013 and Exchange Online (2013)

In previous versions of Exchange accessing the Directory (or Global Address List) with EWS was limited to just resolving a specific entry or expanding a Distribution list. In Exchange 2013 the concept of the persona's has been introduced  http://msdn.microsoft.com/en-us/library/exchange/jj190898%28v=exchg.150%29.aspx . To distill this down a little a persona allows you to have a Contact that can pull its related information from multiple sources while previously everything was just stored in one object in the Exchange Store. There are a number of new EWS operations to go along with personas and the Unified Contact Store the most interesting of these is the FindPeople operation which allows you to do something you couldn't do previously which is enumerate the entire GAL (or any other address list).  At this point I should make the point that the GAL is just one of the data sources that FindPeople can search you can also include searching t...

Clearing the RSS Feeds folder in Exchange using EWS and Powershell

RSS feeds in Outlook is a nice feature that was added in Outlook, but for some organizations it may not be a desirable feature. While you can't delete the RSS Feeds folder itself as its on of Outlooks default folders you can easily remove each of the feeds and items from these folders using EWS's Empty folder operation  http://msdn.microsoft.com/en-us/library/exchange/ff797574(v=exchg.80).aspx . A couple of months back I posted a Language independent way of getting the RSS feeds folder using the PidTagAdditionalRenEntryIdsEx property  http://gsexdev.blogspot.com.au/2013/01/using-pidtagadditionalrenentryidsex.html  . This script can be easily modified to Empty the RSSFeeds folder eg  the following script binds to the RSS Feeds folder and use the Empty Operation with the parameter to also delete all sub folders under the RSS Feeds Folder. - I've put a download of this script here . ## Get the Mailbox to Access from...
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.