Skip to content

Instantly share code, notes, and snippets.

@gscales
Created April 20, 2021 06:13
Show Gist options
  • Save gscales/53b60b022618e55c7eb14dde741b97ae to your computer and use it in GitHub Desktop.
Save gscales/53b60b022618e55c7eb14dde741b97ae to your computer and use it in GitHub Desktop.
Tag for external email messages received EWS examples
Extended property Definition for isExternalSender
$isExternalSender = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Guid]::Parse("41F28F13-83F4-4114-A584-EEDB5A6B0BFF"),"IsExternalSender", [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Boolean)
Using it in FindItems
$ItemPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$ItemPropset.Add($isExternalSender)
$ivItemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)
$ivItemView.PropertySet = $ItemPropset
$fiItems = $Service.FindItems($Folder.Id,$ivItemView)
Using it in Search Filter to get External Email
$sfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo($isExternalSender, $true)
$fiItems = $Service.FindItems($Folder.Id,$sfSearchFilter,$ivItemView)
Search Filter for only Internal Senders
$sfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo($isExternalSender, $true)
$SearchFilterNegate = new-Object Microsoft.Exchange.WebServices.Data.SearchFilter+Not($sfSearchFilter)
$fiItems = $Service.FindItems($Folder.Id,$SearchFilterNegate,$ivItemView)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment