by

Superior Search Folder creation with EWS and Powershell

Superior Search Folder creation with EWS and Powershell Up to now I’ve posted some examples of making SearchFolders in Change with EWS and Powershell within the following publish,  on this publish I need to cowl some extra superior issues you are able to do with EWS and Search Folders.

The very first thing I need to cowl is how you alter the choice on a Search folder from “Show number of unread items” which is the default once you create a search folder in EWS to “Show total number of items”. eg

To alter this selection you might want to set the PidTagExtendedFolderFlags property which is documented in http://msdn.microsoft.com/en-us/library/workplace/cc839880(v=workplace.15).aspx . It is a binary property and also you set this specific choice by altering bit 6-7 on this property. Since you additionally want the SearchFolderGuid on this property the simplest time is to set that is proper after you create the folder. eg

  1. $searchFolder.Save($sfRoot.Id);  
  2. $PR_EXTENDED_FOLDER_FLAGS = new-object Microsoft.Change.WebServices.Knowledge.ExtendedPropertyDefinition(0x36DA, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)  
  3. $psPropset = new-object Microsoft.Change.WebServices.Knowledge.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)    
  4. $psPropset.Add($PR_EXTENDED_FOLDER_FLAGS)  
  5. $searchFolder.Load($psPropset)  
  6. $exVal = $null  
  7. if($SearchFolder.TryGetProperty($PR_EXTENDED_FOLDER_FLAGS,[ref]$exVal)){  
  8.      $newVal = “010402001000” + [System.BitConverter]::ToString($exVal).Change(“-“,“”)  
  9.      $byteVal = HexStringToByteArray($newVal)  
  10.      $SearchFolder.SetExtendedProperty($PR_EXTENDED_FOLDER_FLAGS,$byteVal)  
  11.      $searchFolder.Replace()  
  12. }  
  13. “Folder Created”  

Another fascinating issues you are able to do when utilizing EWS to create search Folders is you may filter on a few of the extra superior Merchandise properties you may’t entry usually utilizing Outlook. For instance the PidTagLastVerbExecuted can be utilized to create a Search folder to seek out all e-mail the place the final motion taken on the Message was to answer to the Sender. Eg this might create a SearchFolder with this sort of filter

  1. $PR_LAST_VERB_EXECUTED = new-object Microsoft.Change.WebServices.Knowledge.ExtendedPropertyDefinition(0x1081, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer)    
  2. $sfItemSearchFilter = new-object Microsoft.Change.WebServices.Knowledge.SearchFilter+IsEqualTo($PR_LAST_VERB_EXECUTED,102)   
  3. #$service.ImpersonatedUserId = new-object Microsoft.Change.WebServices.Knowledge.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)   
  4. $SearchFolder = new-object Microsoft.Change.WebServices.Knowledge.SearchFolder($service);  
  5. $rfRootFolderId = new-object Microsoft.Change.WebServices.Knowledge.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$MailboxName)     
  6. $searchFolder.SearchParameters.RootFolderIds.Add($rfRootFolderId);  
  7. $searchFolder.SearchParameters.Traversal = [Microsoft.Exchange.WebServices.Data.SearchFolderTraversal]::Deep;  
  8. $searchFolder.SearchParameters.SearchFilter = $sfItemSearchFilter  
  9. $searchFolder.DisplayName = $SearchFilterName  
  10. $folderid = new-object Microsoft.Change.WebServices.Knowledge.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::SearchFolders,$MailboxName)     
  11. $sfRoot = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)  
  12. $searchFolder.Save($sfRoot.Id);  

One other fascinating Search Folder you may create on 2013/Workplace365 is utilizing the LatestWordCount property which is not a documented property however you should use it to produce a SearchFolder of all of your wordy emails eg the next would create a SearchFolder of e-mail the place this property indicated the phrase rely of the message was higher than 1000 phrases.

  1. [Guid]$psguid = “23239608-685D-4732-9C55-4C95CB4E8E33”  
  2. $LatestMessageWordCount = new-object Microsoft.Change.WebServices.Knowledge.ExtendedPropertyDefinition($psguid,“LatestMessageWordCount”, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer)    
  3. $sfItemSearchFilter = new-object Microsoft.Change.WebServices.Knowledge.SearchFilter+IsGreaterThan($LatestMessageWordCount,1000)   
  4. #$service.ImpersonatedUserId = new-object Microsoft.Change.WebServices.Knowledge.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)   
  5. $SearchFolder = new-object Microsoft.Change.WebServices.Knowledge.SearchFolder($service);  
  6. $rfRootFolderId = new-object Microsoft.Change.WebServices.Knowledge.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$MailboxName)     
  7. $searchFolder.SearchParameters.RootFolderIds.Add($rfRootFolderId);  
  8. $searchFolder.SearchParameters.Traversal = [Microsoft.Exchange.WebServices.Data.SearchFolderTraversal]::Deep;  
  9. $searchFolder.SearchParameters.SearchFilter = $sfItemSearchFilter  
  10. $searchFolder.DisplayName = $SearchFilterName  
  11. $folderid = new-object Microsoft.Change.WebServices.Knowledge.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::SearchFolders,$MailboxName)     
  12. $sfRoot = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)  
  13. $searchFolder.Save($sfRoot.Id);  

I’ve put a download of full pattern scripts for creating search folder for these two examples right here