I get "The specified object was not found in the store" when I try to access the Master Category List on a newly created mailbox. This is via Powershell EWS on Exchange 2016.
If I open the mailbox and rename one of the categories there is no problem. Guess the XML structure is only created when needed and thus not available before. How can I provoke the creation of the Master Category List?
$folderId = New-Object -TypeName Microsoft.Exchange.WebServices.Data.FolderId -ArgumentList ([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar, $new_mailbox)
$usrConfig = [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind($script:exchService, "CategoryList", $folderId, [Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All)
I get:
ERROR: Exception calling "Bind" with "4" argument(s): "The specified object was not found in the store., The configuration object was not found. Name = CategoryList."
---EDIT--- I have been trying to copy a "template category" from another mailbox but I get stuck.
Here is the code I have so far:
function create-categorylist
{
[CmdLetBinding()]
param
(
$new_mailbox,
$template_mailbox
)
try
{
$folderId = New-Object -TypeName Microsoft.Exchange.WebServices.Data.FolderId -ArgumentList ([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar, $new_mailbox)
#Specify the Calendar folder where the FAI Item is
$usrConfig = [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind($script:exchService, "CategoryList", $folderId, [Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All)
Write-Output "All good"
}
catch
{
# Get Categorylist from Template mailbox
$folderId = New-Object -TypeName Microsoft.Exchange.WebServices.Data.FolderId -ArgumentList ([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar, $template_mailbox)
#Specify the Calendar folder where the FAI Item is
$UsrConfig = [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind($script:exchService, "CategoryList", $folderid, [Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All)
#Get the XML in String Format
$catXMLStr = [System.Text.Encoding]::UTF8.GetString($usrConfig.XmlData)
#Deal with the first character being a Byte Order Mark
$hasBoMark = $false
$boOffset = 0
$boMark = $CatXMLStr.SubString(0, 1)
if ($boMark -ne "<")
{
#log -message "Category XML has BYTE ORDER MARK" -source "CreateCategory()"
$hasBoMark = $true
$boOffset = 1
}
#Parse the XML
[xml]$catXML = $catXMLStr.SubString($boOffset)
#--- Injecting the Categoylist in new mailbox ---
#Write the template Categorylist to mailbox
$new_folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar, $new_mailbox)
##### PROBLEM - How to insert the Categorylist in the mailbox?? ####
#Specify the Calendar folder where the FAI Item is
$new_usrConfig = [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind($script:exchService, "CategoryList", $new_folderid, [Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All)
if ($hasBoMark)
{
$catXMLString = "$boMark$($catXML.OuterXml)"
#log -message "CreateCategory() - Writing category xml with Byte Order Mark : '$catXMLString'" -source "CreateCategory()"
}
else
{
$catXMLString = $catXML.OuterXml
}
$new_usrConfig.XmlData = [System.Text.Encoding]::UTF8.GetBytes($catXMLString)
#Update Item
$new_usrConfig.Update()
}
}