EWS Bascis : Accessing Public Folders and Public Folder Content material

EWS Bascis : Accessing Public Folders and Public Folder Content material In addition to Mailboxes and Archives, Public Folders are one other place chances are you’ll wish to use EWS to enumerate Gadgets to do some enhanced reporting. Constructing on the Enumerate script from the final two publish, this publish will cowl the best way to modify this script to allow entry Public Folder and Public Folder Gadgets.

EWS Modifications

To alter the Mailbox code we’ve to entry public folders requires one massive change within the Mailbox script we’ve the road

$folderid = new-object Microsoft.Trade.WebServices.Information.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$SmtpAddress) 

within the FolderIdFromPath operate. To entry a Public folder we have to change this to

$folderid = new-object Microsoft.Trade.WebServices.Information.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot) 

And that is just about it aside from renaming the operate to PublicFolderIdFromPath that is all it’s a must to do. One factor you’ll be able to’t do with Public Folders vs what you are able to do with Mailboxs and Archive folders is do a DeepTraversal of all of the folders in a folder hierarchy. For the fundamental enumeration script this is not a giant deal as a result of all of the searches are completed at a shallow degree.

Trade 2013 up

For Trade 2013,2016 and Trade On-line there may be one different change you must make to this script which is so as to add the X-AnchorHeader and X-PublicFolderMailbox headers to make sure routing occurs appropriately as per https://msdn.microsoft.com/en-us/library/workplace/dn818490(v=exchg.150).aspx and https://msdn.microsoft.com/en-us/library/workplace/dn818491(v=exchg.150).aspx. It will get just a little difficult right here however as a result of the Hierarchy and content material possibly situated in a special Public Folder Mailboxes it’s a must to use 2 totally different discovery mechanisms each the EWS Managed API uncover like

        $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Trade2013_SP1
$AutoDiscoverService = New-Object Microsoft.Trade.WebServices.Autodiscover.AutodiscoverService($ExchangeVersion);
$creds = New-Object System.Web.NetworkCredential($Credentials.UserName.ToString(),$Credentials.GetNetworkCredential().password.ToString())
$AutoDiscoverService.Credentials = $creds
$AutoDiscoverService.EnableScpLookup = $false;
$AutoDiscoverService.RedirectionUrlValidationCallback = {$true};
$AutoDiscoverService.PreAuthenticate = $true;
$AutoDiscoverService.KeepAlive = $false;
$gsp = $AutoDiscoverService.GetUserSettings($MailboxName,[Microsoft.Exchange.WebServices.Autodiscover.UserSettingName]::AutoDiscoverSMTPAddress);

and a POX Autodiscover (plain previous XML) technique like

        $AutoDiscoverRequest = [System.Net.HttpWebRequest]::Create($AutoDiscoverService.url.ToString().change(".svc",".xml"));
$bytes = [System.Text.Encoding]::UTF8.GetBytes($auDisXML);
$AutoDiscoverRequest.ContentLength = $bytes.Size;
$AutoDiscoverRequest.ContentType = "text/xml";
$AutoDiscoverRequest.UserAgent = "Microsoft Office/16.0 (Windows NT 6.3; Microsoft Outlook 16.0.6001; Pro)";
$AutoDiscoverRequest.Headers.Add("Translate", "F");
$AutoDiscoverRequest.Methodology = "POST";
$AutoDiscoverRequest.Credentials = $creds;
$RequestStream = $AutoDiscoverRequest.GetRequestStream();
$RequestStream.Write($bytes, 0, $bytes.Size);
$AutoDiscoverRequest.AllowAutoRedirect = $truee;
$Response = $AutoDiscoverRequest.GetResponse().GetResponseStream()
$sr = New-Object System.IO.StreamReader($Response)
[XML]$xmlReposne = $sr.ReadToEnd()
if($xmlReposne.Autodiscover.Response.Consumer.AutoDiscoverSMTPAddress -ne $null)
write-host ("Public Folder Content Routing Information Header : " + $xmlReposne.Autodiscover.Response.Consumer.AutoDiscoverSMTPAddress)
$service.HttpHeaders["X-AnchorMailbox"] = $xmlReposne.Autodiscover.Response.Consumer.AutoDiscoverSMTPAddress
$service.HttpHeaders["X-PublicFolderMailbox"] = $xmlReposne.Autodiscover.Response.Consumer.AutoDiscoverSMTPAddress

I’ve put a full copy of this enumerate script up on git hub https://github.com/gscales/Powershell-Scripts/blob/grasp/EnumerateItemsInPublicFolder.ps1

For one instance of what you are able to do with it if we take the pattern from the final publish on ItemAge we will create an ItemAge script for public folder gadgets. eg


Leave a Reply