Creating a brand new folder in EWS and add it to the MyContacts checklist in OWA in Trade 2013/Workplace365

Creating a brand new folder in EWS and add it to the MyContacts checklist in OWA in Trade 2013/Workplace365 The peoples hub is among the new options in Trade 2013 and Trade On-line that’s aimed toward making your life richer. One little quirk in case your creating new folders utilizing EWS is that they will not seem within the My Contacts checklist inOWA eg if I used to be making a folder named aNewContactsFolder you’ll get

To make the brand new Folder you simply created seem within the MyContacts checklist fairly then different contacts you’ll want to set these two but to be documented properties

PeopleHubSortGroupPriority 
PeopleHubSortGroupPriorityVersion

Setting the worth of those two named properties to five and a couple of respectively will make the folder seem underneath My Contacts, if you wish to transfer the folder into different contacts set the values to 10 and a couple of

Here is a pattern script to create a New Folder as a subfolder of a Mailboxes Contacts Folder and set these two properties so the Contact Folder seems underneath MyContacts

To run the script go the emailaddress of the mailbox you wish to run it in opposition to as the primary parameter and the foldername because the second parameter eg use one thing like .createMyContactsFldv2.ps1 jcool@area.com newfolderss

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

  1. ## Get the Mailbox to Entry from the 1st commandline argument  
  2. $NewFolderName = $args[1]  
  3. $MailboxName = $args[0]  
  4.   
  5. ## Load Managed API dll    
  6.   
  7. ###CHECK FOR EWS MANAGED API, IF PRESENT IMPORT THE HIGHEST VERSION EWS DLL, ELSE EXIT  
  8. $EWSDLL = (($(Get-ItemProperty -ErrorAction SilentlyContinue -Path Registry::$(Get-ChildItem -ErrorAction SilentlyContinue -Path ‘Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftExchangeWeb Companies’|Kind-Object Title -Descending| Choose-Object -First 1 -ExpandProperty Title)).‘Set up Listing’) + “Microsoft.Exchange.WebServices.dll”)  
  9. if (Check-Path $EWSDLL)  
  10.     {  
  11.     Import-Module $EWSDLL  
  12.     }  
  13. else  
  14.     {  
  15.     “$(get-date -format yyyyMMddHHmmss):”  
  16.     “This script requires the EWS Managed API 1.2 or later.”  
  17.     “Please download and install the current version of the EWS Managed API from”  
  18.     “http://go.microsoft.com/fwlink/?LinkId=255472”  
  19.     “”  
  20.     “Exiting Script.”  
  21.     exit  
  22.     }  
  23.     
  24. ## Set Trade Model    
  25. $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Trade2010_SP2    
  26.     
  27. ## Create Trade Service Object    
  28. $service = New-Object Microsoft.Trade.WebServices.Information.ExchangeService($ExchangeVersion)    
  29.     
  30. ## Set Credentials to use two choices are availible Option1 to use explict credentials or Possibility 2 use the Default (logged On) credentials    
  31.     
  32. #Credentials Possibility 1 utilizing UPN for the home windows Account    
  33. $psCred = Get-Credential    
  34. $creds = New-Object System.Internet.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())    
  35. $service.Credentials = $creds        
  36.     
  37. #Credentials Possibility 2    
  38. #service.UseDefaultCredentials = $true    
  39.     
  40. ## Select to ignore any SSL Warning points brought on by Self Signed Certificates    
  41.     
  42. ## Code From http://poshcode.org/624  
  43. ## Create a compilation setting  
  44. $Supplier=New-Object Microsoft.CSharp.CSharpCodeProvider  
  45. $Compiler=$Supplier.CreateCompiler()  
  46. $Params=New-Object System.CodeDom.Compiler.CompilerParameters  
  47. $Params.GenerateExecutable=$False  
  48. $Params.GenerateInMemory=$True  
  49. $Params.IncludeDebugInformation=$False  
  50. $Params.ReferencedAssemblies.Add(“System.DLL”) | Out-Null  
  51.   
  52. $TASource=@ 
  53.   namespace Native.ToolkitExtensions.Internet.CertificatePolicy{ 
  54.     public class TrustAll : System.Internet.ICertificatePolicy { 
  55.       public TrustAll() {  
  56.       } 
  57.       public bool CheckValidationResult(System.Internet.ServicePoint sp, 
  58.         System.Safety.Cryptography.X509Certificates.X509Certificates cert,  
  59.         System.Internet.WebRequest req, int downside) { 
  60.         return true; 
  61.       } 
  62.     } 
  63.   } 
  64. @   
  65. $TAResults=$Supplier.CompileAssemblyFromSource($Params,$TASource)  
  66. $TAAssembly=$TAResults.CompiledAssembly  
  67.   
  68. ## We now create an occasion of the TrustAll and connect it to the ServicePointManager  
  69. $TrustAll=$TAAssembly.CreateInstance(“Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll”)  
  70. [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll  
  71.   
  72. ## finish code from http://poshcode.org/624  
  73.     
  74. ## 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    
  75.     
  76. #CAS URL Possibility 1 Autodiscover    
  77. $service.AutodiscoverUrl($MailboxName,{$true})    
  78. “Using CAS Server : “ + $Service.url     
  79.      
  80. #CAS URL Possibility 2 Hardcoded    
  81.     
  82. #$uri=[system.URI] “https://casservername/ews/exchange.asmx”    
  83. #$service.Url = $uri      
  84.     
  85. ## Non-compulsory part for Trade Impersonation    
  86.     
  87. #$service.ImpersonatedUserId = new-object Microsoft.Trade.WebServices.Information.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)   
  88.   
  89.   
  90. #PropDefs   
  91. $PeopleHubSortGroupPriority = new-object Microsoft.Trade.WebServices.Information.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Frequent, “PeopleHubSortGroupPriority”, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);  
  92. $PeopleHubSortGroupPriorityVersion = New-Object Microsoft.Trade.WebServices.Information.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Frequent, “PeopleHubSortGroupPriorityVersion”, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);  
  93.   
  94. # Bind to the Contacts Folder  
  95.   
  96. $folderid= new-object Microsoft.Trade.WebServices.Information.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Contacts,$MailboxName)     
  97. $Contacts = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)  
  98.   
  99. $NewFolder = new-object Microsoft.Trade.WebServices.Information.Folder($service)    
  100. $NewFolder.DisplayName = $NewFolderName    
  101. $NewFolder.FolderClass = “IPF.Contact”  
  102. $NewFolder.SetExtendedProperty($PeopleHubSortGroupPriority,5);  
  103. $NewFolder.SetExtendedProperty($PeopleHubSortGroupPriorityVersion,2);  
  104. $NewFolder.Save($Contacts.Id)    
  105. “Created Folder”  

Leave a Reply