Exchange Web Services 2.0 Using PowerShell

  • Exchange Online and Exchange 2013 development :=> https://msdn.microsoft.com/en-us/library/office/jj162981.aspx
  • Microsoft Exchange Web Services Managed API 2.2 :=> http://www.microsoft.com/en-us/download/details.aspx?id=42951
  • EWS Managed API reference :=> https://msdn.microsoft.com/en-us/library/office/jj220535(v=exchg.80).aspx
  • PowerShell - Script to move items from one folder to another in a user's mailbox :=> http://blogs.msdn.com/b/emeamsgdev/archive/2012/04/27/powershell-script-to-move-items-from-one-folder-to-another-in-a-user-s-mailbox.aspx
  • Quick searching of today's email using Powershell and EWS :=> http://stackoverflow.com/questions/29009265/quick-searching-of-todays-email-using-powershell-and-ews
  • Search-Mailbox :=> https://support.microsoft.com/en-us/kb/2977178
  • Explore the EWS Managed API, EWS, and web services in Exchange :=> https://msdn.microsoft.com/en-us/library/office/jj536567(v=exchg.150).aspx
  • EWS Managed API, EWS, and web services in Exchange :=> https://msdn.microsoft.com/en-us/library/office/dd877012(v=exchg.150).aspx
  • Exchange Online and Exchange 2013 development :=> https://msdn.microsoft.com/en-us/library/office/jj162981.aspx
  • Exporting and importing items by using EWS in Exchange :=> https://msdn.microsoft.com/en-us/library/office/dn672316(v=exchg.150).aspx
  • PowerShell EWS Save as for e-mails :=> http://stackoverflow.com/questions/30725460/powershell-ews-save-as-for-e-mails


/*******************************************************************************************************/
CLS
$searchFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::SentItems)

$vv = New-Object  Microsoft.Exchange.WebServices.Data.FolderView(2,0)
$vv.PropertySet = [Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly
$sendOldSearchFilter = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName, "OLD_DO_NOT_DEL")
$sendOldFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot).FindFolders($sendOldSearchFilter,$vv);

$PropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$PropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text;
$SearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsLessThanOrEqualTo([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeSent,[system.DateTime]::Now.Date.AddDays(-15))

$View =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)
$Mails = 0
do {
    $Mails = $service.FindItems($searchFolder.Id,$SearchFilter,$View)
    $service.LoadPropertiesForItems($Mails,$PropertySet) | Out-Null

    #foreach ($Mail in $Mails.Items | select -First 1) {
    foreach ($Mail in $Mails.Items) {
        $Mail.DisplayTo 
        "$($Mail.Subject) `t  $($Mail.DateTimeSent)"
        "`n"
        #"Body        : " + $Mail.Body
        #$Mail.Move($sendOldFolder.Id) | Out-Null
    }

    $View.Offset += $Mails.Items.Count
} while($Mails.MoreAvailable -eq $true)
#} while($false)
/*******************************************************************************************************/