eDiscovery is one of the new features in Exchange 2013 aimed at both improving the search experience and also helping deal with Big Data in a mailbox or mailboxes (which is kind of like the Sun in that its just keeps getting bigger and will one day consume us all).
With eDiscovery in EWS you can perform two types of searches a
If your doing a Preview Query with a very generic search predicate that is going to be returning many preview Items and because of the size of these results they will returned as separate paged results sets. This will mean you will need to make multiple search requests to navigate thought the result set pages.
To tell the server you want the next Page in the Results set you need to use the PageItemReference . The PageItemReference value needs to be set to the SortValue of the Last Preview-item returned by the previous page.
I've put together a couple of Managed API samples for this one is a C# example and the other is a Template Powershell script you can use to do a eDiscovery on one mailbox. These sample pages items back in lots of 100, you can adjust this value but I wouldn't go much over 1000. I've put a download of the code here, the script looks like.
With eDiscovery in EWS you can perform two types of searches a
- Estimate Query - Which will return information about the number of hits for a particular KQL query.
- Preview Query - Will return your query hits as PreviewItems which you can then use to show more information about each hit.
If your doing a Preview Query with a very generic search predicate that is going to be returning many preview Items and because of the size of these results they will returned as separate paged results sets. This will mean you will need to make multiple search requests to navigate thought the result set pages.
To tell the server you want the next Page in the Results set you need to use the PageItemReference . The PageItemReference value needs to be set to the SortValue of the Last Preview-item returned by the previous page.
I've put together a couple of Managed API samples for this one is a C# example and the other is a Template Powershell script you can use to do a eDiscovery on one mailbox. These sample pages items back in lots of 100, you can adjust this value but I wouldn't go much over 1000. I've put a download of the code here, the script looks like.
- ## Get the Mailbox to Access from the 1st commandline argument
- $MailboxName = $args[0]
- $KQL = "Subject:test";
- $SearchableMailboxString = $MailboxName;
- ## Load Managed API dll
- Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"
- ## Set Exchange Version
- $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013
- ## Create Exchange Service Object
- $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)
- ## Set Credentials to use two options are availible Option1 to use explict credentials or Option 2 use the Default (logged On) credentials
- #Credentials Option 1 using UPN for the windows Account
- $psCred = Get-Credential
- $creds = New-Object System.Net.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())
- $service.Credentials = $creds
- #Credentials Option 2
- #service.UseDefaultCredentials = $true
- ## Choose to ignore any SSL Warning issues caused by Self Signed Certificates
- ## Code From http://poshcode.org/624
- ## Create a compilation environment
- $Provider=New-Object Microsoft.CSharp.CSharpCodeProvider
- $Compiler=$Provider.CreateCompiler()
- $Params=New-Object System.CodeDom.Compiler.CompilerParameters
- $Params.GenerateExecutable=$False
- $Params.GenerateInMemory=$True
- $Params.IncludeDebugInformation=$False
- $Params.ReferencedAssemblies.Add("System.DLL") | Out-Null
- $TASource=@'
- namespace Local.ToolkitExtensions.Net.CertificatePolicy{
- public class TrustAll : System.Net.ICertificatePolicy {
- public TrustAll() {
- }
- public bool CheckValidationResult(System.Net.ServicePoint sp,
- System.Security.Cryptography.X509Certificates.X509Certificate cert,
- System.Net.WebRequest req, int problem) {
- return true;
- }
- }
- }
- '@
- $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
- $TAAssembly=$TAResults.CompiledAssembly
- ## We now create an instance of the TrustAll and attach it to the ServicePointManager
- $TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
- [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll
- ## end code from http://poshcode.org/624
- ## Set the URL of the CAS (Client Access Server) to use two options are availbe to use Autodiscover to find the CAS URL or Hardcode the CAS to use
- #CAS URL Option 1 Autodiscover
- $service.AutodiscoverUrl($MailboxName,{$true})
- "Using CAS Server : " + $Service.url
- #CAS URL Option 2 Hardcoded
- #$uri=[system.URI] "https://casservername/ews/exchange.asmx"
- #$service.Url = $uri
- ## Optional section for Exchange Impersonation
- #$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)
- $gsMBResponse = $service.GetSearchableMailboxes($SearchableMailboxString, $false);
- $gsMBResponse
- $msbScope = New-Object Microsoft.Exchange.WebServices.Data.MailboxSearchScope[] $gsMBResponse.SearchableMailboxes.Length
- $mbCount = 0;
- foreach ($sbMailbox in $gsMBResponse.SearchableMailboxes)
- {
- $msbScope[$mbCount] = New-Object Microsoft.Exchange.WebServices.Data.MailboxSearchScope($sbMailbox.ReferenceId, [Microsoft.Exchange.WebServices.Data.MailboxSearchLocation]::All);
- $mbCount++;
- }
- $smSearchMailbox = New-Object Microsoft.Exchange.WebServices.Data.SearchMailboxesParameters
- $mbq = New-Object Microsoft.Exchange.WebServices.Data.MailboxQuery($KQL, $msbScope);
- $mbqa = New-Object Microsoft.Exchange.WebServices.Data.MailboxQuery[] 1
- $mbqa[0] = $mbq
- $smSearchMailbox.SearchQueries = $mbqa;
- $smSearchMailbox.PageSize = 100;
- $smSearchMailbox.PageDirection = [Microsoft.Exchange.WebServices.Data.SearchPageDirection]::Next;
- $smSearchMailbox.PerformDeduplication = $false;
- $smSearchMailbox.ResultType = [Microsoft.Exchange.WebServices.Data.SearchResultType]::PreviewOnly;
- $srCol = $service.SearchMailboxes($smSearchMailbox);
- if ($srCol[0].Result -eq [Microsoft.Exchange.WebServices.Data.ServiceResult]::Success)
- {
- if ($srCol[0].SearchResult.ItemCount -gt 0)
- {
- do
- {
- $smSearchMailbox.PageItemReference = $srCol[0].SearchResult.PreviewItems[$srCol[0].SearchResult.PreviewItems.Length - 1].SortValue;
- foreach ($PvItem in $srCol[0].SearchResult.PreviewItems) {
- Write-Host ($PvItem.Subject);
- }
- $srCol = $service.SearchMailboxes($smSearchMailbox);
- Write-Host("Items Remaining : " + $srCol[0].SearchResult.ItemCount);
- } while ($srCol[0].SearchResult.ItemCount-gt 0 );
- }
- }