Skip to main content

PowerShell + EAS : Getting Started

This is the first post on a series of blog posts concentrated around understanding Exchange ActiveSync Protocol as this is the underlying protocol which Mobile devices use in order to connect to the Exchange Server.

The whole idea is to be able to craft EAS requests and parse the Server responses using PowerShell in order to understand the protocol better.

Hint - Take a look at the cmdlet Invoke-WebRequest, it will be used to craft the Web requests later on.


Why I want to do this ?
Because when you start poking around you learn the Product better :).

This is a getting started post and I am following and porting most of the code already written in C# at MobilityDojo.net to PowerShell.

This post is about giving you a hang of how to make Web Requests to an Exchange Server's EAS endpoint and parse them to get insight in the process.

Now if you setup mail for a User in a Mobile device and use Fiddler as reverse proxy to analyze the communication , you will see the below :



Skip Verification Checks


Add the below line of code to your Script if you don't bother to perform the Server certificate validation, this is only for testing Environments.


001
002
003

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}



Create the Authorization header 




Enter the credentials of a mail enabled User in (Domain\Username or UserPrincipalName format )


001
002
003
004
$Credential = Get-Credential
$EncodedUsernamePassword = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($('{0}:{1}' -f $Credential.UserName, $Credential.GetNetworkCredential().Password)))
$Headers = @{'Authorization' = "Basic $($EncodedUsernamePassword)"}


Hit /Microsoft-Server-ActiveSync




001
002
$URL = 'https://dexexch.dex.com/Microsoft-Server-ActiveSync'
$response = Invoke-WebRequest -Uri $URL -Headers $Headers -Method Options

Now take a look at the headers returned from the Exchange Server 


PS>$response = Invoke-WebRequest -Uri $URL -Headers $Headers -Method Options                                                                
PS>$response.Headers                                                                                                                      
                                                                                                                                            
Key                                                                    Value                                                                
---                                                                    -----                                                                
Allow                                                                  OPTIONS,POST                                                         
MS-Server-ActiveSync                                                   14.2                                                                 
MS-ASProtocolVersions                                                  2.0,2.1,2.5,12.0,12.1,14.0,14.1                                      
MS-ASProtocolCommands                                                  Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,C...
Public                                                                 OPTIONS,POST                                                         
Content-Length                                                         0                                                                    
Cache-Control                                                          private                                                              
Date                                                                   Thu, 26 Feb 2015 14:59:11 GMT                                        
Server                                                                 Microsoft-IIS/7.5                                                    
X-AspNet-Version                                                       2.0.50727                                                            
X-Powered-By                                                           ASP.NET                                                              
                                                                                                                                            


In a typical EAS communication after Autodiscovery takes place this is the first step as the Client determines the EAS commands & version supported by the remote Exchange Server. We will be using this code over when we start working through the EAS protocol.


Resources:

Original post using C# @MobilityDojo.net
http://mobilitydojo.net/2011/08/16/exchange-activesync-building-blockswarming-up/


Working with .NET call backs
http://www.nivot.org/post/2009/07/18/PowerShell20RCWorkingWithNETCallbacksPart1Synchronous

Popular posts from this blog

Test connectivity via a specific network interface

Recently while working on a Private cloud implementation, I came across a scenario where I needed to test connectivity of a node to the AD/DNS via multiple network adapters.  Many of us would know that having multiple network routes is usually done to take care of redundancy. So that if a network adapter goes down, one can use the other network interface to reach out to the node. In order to make it easy for everyone to follow along, below is an analogy for the above scenario: My laptop has multiple network adapters (say Wi-Fi and Ethernet) connected to the same network. Now how do I test connectivity to a Server on the network only over say Wi-Fi network adapter?

PowerShell + SCCM : Run CM cmdlets remotely

Today I saw a tweet about using implicit remoting to load the Configuration Manager on my machine by Justin Mathews . It caught my eye as I have never really tried it, but theoretically it can be done. Note - The second tweet says "Cannot find a provider with the name CMSite", resolution to which is in the Troubleshooting section at the end.

Azure DevOps Tips & Tricks - Find private REST APIs

Original source -  Azure DevOps Tip - Find private APIs Often working with Azure DevOps, I hit a wall trying to automate some tasks but there are no REST API's made public yet. It was one of those task of automating creation of Environments in multi-stage YAML based pipelines in AzDO. Quick research reveals that this has been requested in uservoice  (please upvote). Let's see one of the very simple ways to discover some of these APIs.