by

A glance into Conversations with EWS and Powershell in a Mailbox

A glance into Conversations with EWS and Powershell in a Mailbox Dialog views in electronic mail purchasers have change into par for the course as of late, whereas I am personally not an important fan it may be a helpful function to make use of when  Mailbox information. With EWS from Change 2010 you need to use the devoted EWS operations that are documented http://msdn.microsoft.com/en-us/library/workplace/dn610351(v=exchg.150).aspx . In Change 2013 the dialog operations have been enhanced to supply extra performance akin to the flexibility to use an AQS QueryString to filter the outcomes plus additionally the flexibility to use actions to dialog like making use of classes or a selected retention tag.

One attention-grabbing factor you possibly can apply these dialog operations to is Mailbox statistics another way by  the operation of Mailboxes to see how engaged the house owners or customers of the Mailboxes are, by seeing how engaged within the dialog which can be occurring within the Mailbox. eg

The FindConversation operation in Change will return info such because the MessageCount and Measurement in a selected folder in addition to the GlobalCount and Sizes throughout all folders in a Mailbox for a dialog.That is pattern of a script that makes use of the findconversation operation to do some statistical sampling of dialog information. So what this does is

  • Does a FindConversation on the Inbox folder to seize the dialog info for the Inbox
  • Does a FindConversation on the SentItems Folder to seize the dialog stats for the Despatched Mail
  • Combines the outcomes collectively to work out the participation fee within the dialog based mostly on the quantity of Messages this explicit mailbox despatched.
  • For Change 2013 you too can question based mostly on the acquired date of the e-mail so you possibly can have a look at the final 7 days price or information and many others.

So you possibly can run the script like this to look at the entire of the Inbox

 .converstats.ps1 person@area.onmicrosoft.com

or you need to use a Date to specify how a lot information you wish to have a look at eg for the final 7 days use

.converstats.ps1 person@area.onmicrosoft.com (get-date).AddDays(-7)

Within the script itself I’ve bought it set to solely report on dialog with a messagecount larger then Three and kind the dialog by the participation fee you possibly can alter this by fidgeting with the next line

$Script:rptcollection.Values | The place-Object {$_.InboxMessageCount -gt 3} | Type-Object ParticipationRate -Descending | Export-Csv -NoTypeInformation -Path c:Temp$MailboxName-cnvStats.csv

I’ve put a download this script right here the script itself seems like

  1. $MailboxName = $args[0]  
  2. $StartDate = $args[1]  
  3.   
  4.   
  5. ## Get the Mailbox to Entry from the 1st commandline argument  
  6.   
  7. ## Load Managed API dll    
  8.   
  9. ###CHECK FOR EWS MANAGED API, IF PRESENT IMPORT THE HIGHEST VERSION EWS DLL, ELSE EXIT  
  10. $EWSDLL = (($(Get-ItemProperty -ErrorAction SilentlyContinue -Path Registry::$(Get-ChildItem -ErrorAction SilentlyContinue -Path ‘Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftExchangeWeb Companies’|Type-Object Title -Descending| Choose-Object -First 1 -ExpandProperty Title)).‘Set up Listing’) + “Microsoft.Exchange.WebServices.dll”)  
  11. if (Take a look at-Path $EWSDLL)  
  12.     {  
  13.     Import-Module $EWSDLL  
  14.     }  
  15. else  
  16.     {  
  17.     “$(get-date -format yyyyMMddHHmmss):”  
  18.     “This script requires the EWS Managed API 1.2 or later.”  
  19.     “Please download and install the current version of the EWS Managed API from”  
  20.     “http://go.microsoft.com/fwlink/?LinkId=255472”  
  21.     “”  
  22.     “Exiting Script.”  
  23.     exit  
  24.     }  
  25.     
  26. ## Set Change Model    
  27. $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Change2013_SP1  
  28.     
  29. ## Create Change Service Object    
  30. $service = New-Object Microsoft.Change.WebServices.Information.ExchangeService($ExchangeVersion)    
  31.     
  32. ## Set Credentials to use two choices are availible Option1 to use explict credentials or Possibility 2 use the Default (logged On) credentials    
  33.     
  34. #Credentials Possibility 1 utilizing UPN for the home windows Account    
  35. $psCred = Get-Credential    
  36. $creds = New-Object System.Internet.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())    
  37. $service.Credentials = $creds        
  38.     
  39. #Credentials Possibility 2    
  40. #service.UseDefaultCredentials = $true    
  41.     
  42. ## Select to ignore any SSL Warning points brought on by Self Signed Certificates    
  43.     
  44. ## Code From http://poshcode.org/624  
  45. ## Create a compilation atmosphere  
  46. $Supplier=New-Object Microsoft.CSharp.CSharpCodeProvider  
  47. $Compiler=$Supplier.CreateCompiler()  
  48. $Params=New-Object System.CodeDom.Compiler.CompilerParameters  
  49. $Params.GenerateExecutable=$False  
  50. $Params.GenerateInMemory=$True  
  51. $Params.IncludeDebugInformation=$False  
  52. $Params.ReferencedAssemblies.Add(“System.DLL”) | Out-Null  
  53.   
  54. $TASource=@ 
  55.   namespace Native.ToolkitExtensions.Internet.CertificatePolicy{ 
  56.     public class TrustAll : System.Internet.ICertificatePolicy { 
  57.       public TrustAll() {  
  58.       } 
  59.       public bool CheckValidationResult(System.Internet.ServicePoint sp, 
  60.         System.Safety.Cryptography.X509Certificates.X509Certificates cert,  
  61.         System.Internet.WebRequest req, int downside) { 
  62.         return true; 
  63.       } 
  64.     } 
  65.   } 
  66. @   
  67. $TAResults=$Supplier.CompileAssemblyFromSource($Params,$TASource)  
  68. $TAAssembly=$TAResults.CompiledAssembly  
  69.   
  70. ## We now create an occasion of the TrustAll and connect it to the ServicePointManager  
  71. $TrustAll=$TAAssembly.CreateInstance(“Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll”)  
  72. [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll  
  73.   
  74. ## finish code from http://poshcode.org/624  
  75.     
  76. ## Set the URL of the CAS (Consumer Entry Server) to use two choices are availbe to use Autodiscover to discover the CAS URL or Hardcode the CAS to use    
  77.     
  78. #CAS URL Possibility 1 Autodiscover    
  79. $service.AutodiscoverUrl($MailboxName,{$true})    
  80. “Using CAS Server : “ + $Service.url     
  81.      
  82. #CAS URL Possibility 2 Hardcoded    
  83.     
  84. #$uri=[system.URI] “https://casservername/ews/exchange.asmx”    
  85. #$service.Url = $uri      
  86.     
  87. ## Non-obligatory part for Change Impersonation    
  88.     
  89. #$service.ImpersonatedUserId = new-object Microsoft.Change.WebServices.Information.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)   
  90. if($StartDate -ne $null){  
  91.     $AQSString = “received:>” + $StartDate.ToString(“yyyy-MM-dd”)   
  92.     $AQSString  
  93. }  
  94. # Bind to the Inbox Folder  
  95. $Script:rptcollection = @{}  
  96. $folderid= new-object Microsoft.Change.WebServices.Information.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)     
  97. $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)  
  98. # Bind to the SentItems Folder  
  99. $folderid= new-object Microsoft.Change.WebServices.Information.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::SentItems,$MailboxName)     
  100. $SentItems = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)  
  101.   
  102. perform Course of-Folder{    
  103.     param (    
  104.             $FolderId = “$( throw ‘SMTPAddress is a mandatory Parameter’ )”,  
  105.             $IsSentItems = “$( throw ‘SMTPAddress is a mandatory Parameter’ )”  
  106.           )    
  107.     course of{   
  108.         $cnvItemView = New-Object Microsoft.Change.WebServices.Information.ConversationIndexedItemView(1000)  
  109.         $cnvs = $null;  
  110.         do  
  111.         {  
  112.             $cnvs = $service.FindConversation($cnvItemView$FolderId,$AQSString);  
  113.             “Number of Conversation returned “ + $cnvs.Depend  
  114.             foreach($cnv in $cnvs){  
  115.                 $rptobj = $cnv | choose Matter,LastDeliveryTime,UniqueSenders,UniqueRecipients,InboxMessageCount,GlobalMessageCount,InboxMessageSize,SentItemsMessageCount,SentItemsMessageSize,ParticipationRate      
  116.                 if($Script:rptcollection.Comprises($cnv.Id.UniqueId)-eq $false){  
  117.                     if($IsSentItems){  
  118.                         $rptobj.SentItemsMessageCount = $cnv.MessageCount  
  119.                         $rptobj.SentItemsMessageSize = $cnv.Measurement  
  120.                         $rptobj.InboxMessageCount = 0  
  121.                         $rptobj.InboxMessageSize = 0  
  122.                         $rptobj.LastDeliveryTime = $cnv.LastDeliveryTime  
  123.                         $rptobj.UniqueSenders = $cnv.GlobalUniqueSenders  
  124.                         $rptobj.UniqueRecipients = $cnv.GlobalUniqueRecipients  
  125.                     }  
  126.                     else{  
  127.                         $rptobj.InboxMessageCount = $cnv.MessageCount  
  128.                         $rptobj.InboxMessageSize = $cnv.Measurement  
  129.                         $rptobj.SentItemsMessageCount = 0  
  130.                         $rptobj.SentItemsMessageSize = 0  
  131.                         $rptobj.LastDeliveryTime = $cnv.LastDeliveryTime  
  132.                         $rptobj.UniqueSenders = $cnv.GlobalUniqueSenders  
  133.                         $rptobj.UniqueRecipients = $cnv.GlobalUniqueRecipients  
  134.                     }  
  135.                     $Script:rptcollection.Add($cnv.Id.UniqueId,$rptobj)  
  136.                 }  
  137.                 else{  
  138.                     if($IsSentItems){  
  139.                         $Script:rptcollection[$cnv.Id.UniqueId].SentItemsMessageCount = $cnv.MessageCount  
  140.                         $Script:rptcollection[$cnv.Id.UniqueId].SentItemsMessageSize = $cnv.Measurement  
  141.                     }  
  142.                     else{  
  143.                         $Script:rptcollection[$cnv.Id.UniqueId].InboxMessageCount = $cnv.MessageCount  
  144.                         $Script:rptcollection[$cnv.Id.UniqueId].InboxMessageSize = $cnv.Measurement  
  145.                     }  
  146.                        
  147.                 }                 
  148.               
  149.             }  
  150.             $cnvItemView.Offset += $cnvs.Depend  
  151.         }whereas($cnvs.Depend -gt 0)  
  152.     }  
  153. }  
  154. Course of-Folder -FolderId $Inbox.Id -IsSentItems $false  
  155. Course of-Folder -FolderId $SentItems.Id -IsSentItems $true  
  156. foreach($worth in $Script:rptcollection.Values){  
  157.     if($worth.GlobalMessageCount -gt 0 -band $worth.SentItemsMessageCount -gt 0){  
  158.         $worth.ParticipationRate = [Math]::spherical((($worth.SentItemsMessageCount/$worth.GlobalMessageCount) * 100))  
  159.     }  
  160.     else{  
  161.         $worth.ParticipationRate = 0  
  162.     }  
  163. }  
  164. $Script:rptcollection.Values | The place-Object {$_.InboxMessageCount -gt 3} | Type-Object ParticipationRate -Descending | Export-Csv -NoTypeInformation -Path c:Temp$MailboxName-cnvStats.csv  
  165.