A colleague shared a blog post and asked me a script to get high priority email using PowerShell? Well, it’s the same way ย by modifying the search filter as required as shown below.
$SearchFilter = [Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo]::new([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::Importance, "High")
and the below is the view to get the number of email we need from the inbox – In our case just one!
$View = [Microsoft.Exchange.WebServices.Data.ItemView]::new(1)
Hey, I need a phone call for a high priority email and it should read the message! That’s a Friday fever!ย For any IT Professional major incidents are not new ๐ check the below email body ๐ let’s get a call for the same !
Email Body
Here is the sample code !
$Credential = Get-Credential "Chendrayan.Venkatesan@contoso.com" $Service = [Microsoft.Exchange.WebServices.Data.ExchangeService]::new([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1) $Service.Credentials = [System.Net.NetworkCredential]::new($Credential.UserName,$Credential.Password) $Service.AutodiscoverUrl($UserID,{$true}) $Service.Url = "https://outlook.office365.com/EWS/Exchange.asmx" $Folder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($Service,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox) $View = [Microsoft.Exchange.WebServices.Data.ItemView]::new(1) $SearchFilter = [Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo]::new([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::Importance, "High") $Results = $Service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$SearchFilter,$View) $ItemId = $Results.Items[0].Id.UniqueId # Fun and it's Fun $Call = $Service.UnifiedMessaging.PlayOnPhone($ItemId, "+31<Number>") $Call.Refresh()
Enjoy PowerShell!
One thought on “Get High Priority Email Message as a Phone Call using EWS API and PowerShell”
Appreciate the recommendation. Will try it out.|