Created
September 6, 2018 17:40
-
-
Save bill-long/28e561a982823417bc81f8c1b5bb7fcf to your computer and use it in GitHub Desktop.
Reproduce an error binding to a calendar public folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### | |
# Change as needed | |
$folderPath = "\Bill\Some Calendar" | |
$user = "bill@contoso.com" | |
# | |
##### | |
Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll" | |
$password = $host.ui.PromptForCredential("Credentials", "Please enter your password to authenticate to EWS.", $user, "").GetNetworkCredential().Password | |
$exchService = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2016) | |
$exchService.Credentials = new-object System.Net.NetworkCredential($user, $password, "") | |
$exchService.AutoDiscoverUrl($user, {$true}) | |
$pfsRoot = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($exchService, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot) | |
$tinyView = new-object Microsoft.Exchange.WebServices.Data.FolderView(2) | |
$displayNameProperty = [Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName | |
# Find the folder | |
$tinyView = new-object Microsoft.Exchange.WebServices.Data.FolderView(2) | |
$displayNameProperty = [Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName | |
$folderPathSplits = $FolderPath.Split(@('\')) | |
$folder = $pfsRoot # Starting from the root | |
for ($x = 1; $x -lt $folderPathSplits.Length;$x++) | |
{ | |
$filter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo($displayNameProperty, $folderPathSplits[$x]) | |
$results = $folder.FindFolders($filter, $tinyView) | |
if ($results.TotalCount -gt 1) | |
{ | |
("Ambiguous name: " + $folderPathSplits[$x]) | |
return | |
} | |
elseif ($results.TotalCount -lt 1) | |
{ | |
("Folder not found: " + $folderPathSplits[$x]) | |
return | |
} | |
$folder = $results.Folders[0] | |
} | |
# At this point, the result of the folder we specified is in $folder | |
# Now try to bind to that Id | |
[Microsoft.Exchange.WebServices.Data.Folder]::Bind($exchService, $folder.Id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment