Get High Priority Email Message as a Phone Call using EWS API and PowerShell

baby-phone-scam

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

2016-10-28_13-05-55

 

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!

Leave a Reply

Your email address will not be published. Required fields are marked *