by

Looking out based mostly on Classes in EWS

Looking out based mostly on Classes in EWS The Classes or Key phrases properties on a Mailbox Merchandise is among the extra generally used Merchandise properties in Alternate. If you need to seek for Gadgets with a selected Class set it does current some challenges in EWS.

With EWS you will have three totally different search strategies, the primary being Restrictions (or SearchFilter’s in case your utilizing the Managed API) that work like MAPI restrictions though you’ll be able to’t construct restriction which might be 100% equal to what you’ll be able to in MAPI. One specific case is with the Classes property, as a result of this can be a Multi-Valued property (or String Array) the IsEqual and Accommodates Restrictions wont work just like the Sproperty restriction in MAPI http://msdn.microsoft.com/en-us/library/workplace/cc815385(v=workplace.15).aspx

So the following sort of Search you are able to do is a Search of a Mailbox folder utilizing an AQS querystring which basically does an Index search. As a result of the Classes property is an Listed property this can work fantastic for Classes. The thrid sort of Search you are able to do is eDiscovery in Alternate 2013 which I will cowl in one other submit

The next script does a search of the the Inbox folder for a selected Key phrase utilizing the AQS question

“System.Category:Categorytolookfor”

It additionally does a consumer facet validation to make sure no false positives are included. To run the script simply cross within the title of the mailbox you need to search and the Class to seek for (enclosed in ” if there’s a house) eg .SearchCategory.ps1 glen@area.com ‘inexperienced class’ . The script will output a CSV report of all of the messages founds with that individual Class set.

I’ve put a download of this script right here the code itself appears to be like like

  1. ## Get the Mailbox to Entry from the 1st commandline argument  
  2.   
  3. $MailboxName = $args[0]  
  4. $CategoryToFind = $args[1]  
  5.   
  6. ## Load Managed API dll    
  7.   
  8. ###CHECK FOR EWS MANAGED API, IF PRESENT IMPORT THE HIGHEST VERSION EWS DLL, ELSE EXIT  
  9. $EWSDLL = (($(Get-ItemProperty -ErrorAction SilentlyContinue -Path Registry::$(Get-ChildItem -ErrorAction SilentlyContinue -Path ‘Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftExchangeWeb Providers’|Kind-Object Identify -Descending| Choose-Object -First 1 -ExpandProperty Identify)).‘Set up Listing’) + “Microsoft.Exchange.WebServices.dll”)  
  10. if (Take a look at-Path $EWSDLL)  
  11.     {  
  12.     Import-Module $EWSDLL  
  13.     }  
  14. else  
  15.     {  
  16.     “$(get-date -format yyyyMMddHHmmss):”  
  17.     “This script requires the EWS Managed API 1.2 or later.”  
  18.     “Please download and install the current version of the EWS Managed API from”  
  19.     “http://go.microsoft.com/fwlink/?LinkId=255472”  
  20.     “”  
  21.     “Exiting Script.”  
  22.     exit  
  23.     }  
  24.     
  25. ## Set Alternate Model    
  26. $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Alternate2010_SP2    
  27.     
  28. ## Create Alternate Service Object    
  29. $service = New-Object Microsoft.Alternate.WebServices.Information.ExchangeService($ExchangeVersion)    
  30.     
  31. ## Set Credentials to use two choices are availible Option1 to use explict credentials or Possibility 2 use the Default (logged On) credentials    
  32.     
  33. #Credentials Possibility 1 utilizing UPN for the home windows Account    
  34. $psCred = Get-Credential    
  35. $creds = New-Object System.Web.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())    
  36. $service.Credentials = $creds        
  37.     
  38. #Credentials Possibility 2    
  39. #service.UseDefaultCredentials = $true    
  40.     
  41. ## Select to ignore any SSL Warning points brought on by Self Signed Certificates    
  42.     
  43. ## Code From http://poshcode.org/624  
  44. ## Create a compilation setting  
  45. $Supplier=New-Object Microsoft.CSharp.CSharpCodeProvider  
  46. $Compiler=$Supplier.CreateCompiler()  
  47. $Params=New-Object System.CodeDom.Compiler.CompilerParameters  
  48. $Params.GenerateExecutable=$False  
  49. $Params.GenerateInMemory=$True  
  50. $Params.IncludeDebugInformation=$False  
  51. $Params.ReferencedAssemblies.Add(“System.DLL”) | Out-Null  
  52.   
  53. $TASource=@ 
  54.   namespace Native.ToolkitExtensions.Web.CertificatePolicy{ 
  55.     public class TrustAll : System.Web.ICertificatePolicy { 
  56.       public TrustAll() {  
  57.       } 
  58.       public bool CheckValidationResult(System.Web.ServicePoint sp, 
  59.         System.Safety.Cryptography.X509Certificates.X509Certificates cert,  
  60.         System.Web.WebRequest req, int downside) { 
  61.         return true; 
  62.       } 
  63.     } 
  64.   } 
  65. @   
  66. $TAResults=$Supplier.CompileAssemblyFromSource($Params,$TASource)  
  67. $TAAssembly=$TAResults.CompiledAssembly  
  68.   
  69. ## We now create an occasion of the TrustAll and connect it to the ServicePointManager  
  70. $TrustAll=$TAAssembly.CreateInstance(“Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll”)  
  71. [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll  
  72.   
  73. ## finish code from http://poshcode.org/624  
  74.     
  75. ## Set the URL of the CAS (Shopper Entry Server) to use two choices are availbe to use Autodiscover to discover the CAS URL or Hardcode the CAS to use    
  76.     
  77. #CAS URL Possibility 1 Autodiscover    
  78. $service.AutodiscoverUrl($MailboxName,{$true})    
  79. “Using CAS Server : “ + $Service.url     
  80.      
  81. #CAS URL Possibility 2 Hardcoded    
  82.     
  83. #$uri=[system.URI] “https://casservername/ews/exchange.asmx”    
  84. #$service.Url = $uri      
  85.     
  86. ## Optionally available part for Alternate Impersonation    
  87.     
  88. #$service.ImpersonatedUserId = new-object Microsoft.Alternate.WebServices.Information.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)   
  89.   
  90. $AQSString = “System.Category:`”” + $CategoryToFind + “`“”  
  91. # Bind to the Inbox Folder  
  92. $folderid= new-object Microsoft.Alternate.WebServices.Information.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)     
  93. $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)  
  94. $rptCollection = @()  
  95. #Outline ItemView to retrive simply 1000 Gadgets      
  96. $ivItemView =  New-Object Microsoft.Alternate.WebServices.Information.ItemView(1000)      
  97. $fiItems = $null      
  98. do{      
  99.     $fiItems = $service.FindItems($Inbox.Id,$AQSString,$ivItemView)      
  100.     #[Void]$service.LoadPropertiesForItems($fiItems,$psPropset)    
  101.     foreach($Merchandise in $fiItems.Gadgets){  
  102.         #Validate actual Class Match  
  103.         $match = $false  
  104.         foreach($cat in $Merchandise.Classes){  
  105.             if($cat.ToLower() -eq $CategoryToFind.ToLower()){  
  106.                 $match = $true;  
  107.             }  
  108.         }  
  109.         if($match) Choose DateTimeReceived,From,Topic,Dimension,Classes    
  110.             $rptObj.DateTimeReceived = $Merchandise.DateTimeReceived    
  111.             $rptObj.From  = $Merchandise.From.Identify    
  112.             $rptObj.Topic = $Merchandise.Topic    
  113.             $rptObj.Dimension = $Merchandise.Dimension  
  114.             $rptObj.Classes = [system.String]::Be a part of(“,”,$Merchandise.Classes)  
  115.             $rptCollection += $rptObj  
  116.           
  117.     }      
  118.     $ivItemView.Offset += $fiItems.Gadgets.Rely      
  119. }whereas($fiItems.MoreAvailable -eq $true)   
  120. $rptCollection | Export-Csv -NoTypeInformation -Path c:temp$MailboxName-CategoryReport.csv  
  121. Write-Host “Report Saved to c:temp$MailboxName-CategoryReport.csv”