Question

Using Managed EWS 2.0, I'm trying to write some code to create, delete and mail-enable Public Folders on Exchange 2010. However, according to Exchange MVP Glen Scales, mail-enabling a folder is only possible using PowerShell cmdlets, which can be invoked from my C# code. So far, so good.

However, I'm a bit confused when mapping between my EWS Folder objects (which have a FolderId) and PowerShell's Enable-MailPublicFolder cmdlet, which expects a GUID or a Folder Path as identity parameters. I'm not sure how to map between the two.

EWS has a ConvertIDs method, but that seems to be able to generate various formats (EwsId, EntryId, OwaId) which don't seem relevant to PowerShell.

Apart from manually generating a Folder Path from my given folder, which is easy but feels clunky given that I have an explicit identifier for the folder, is there a way to convert my Folder ID to a format usable by the Exchange Cmdlets?

Was it helpful?

Solution

Ok, with the help of Glen Scales I got this to work. It seems that PowerShell's PublicFolderIdParameter type (the type of the Identity parameter) accepts a sequence of Hexadecimal characters representing the EntryID. So to translate an EWS ID to a PowerShell-accepted ID, we can use this code:

Folder myFolder = Folder.Bind("whatever");
var ewsId = new AlternatePublicFolderId(IdFormat.EwsId, myFolder.Id.UniqueId);
var hexId = _service.ConvertId(ewsId, IdFormat.HexEntryId) as AlternatePublicFolderId;
string idForPowerShell = hexId.FolderId;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top