Morten Breiner
Morten Breiner

Reputation: 1

Exchange 2016. Provoke creation of Master Category List?

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()  
    }
}

Upvotes: 0

Views: 525

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

The category list gets created by the client either Outlook or OWA, EWS doesn't have the ability to create it automatically at the server. You can create it yourself using EWS (or use a template version and import that) the format is documented in https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxocfg/eb7cac90-6200-4ac3-8f3c-6c808c681c8b

viewstate exmaple

$folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)     
$SfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.ItemSchema]::ItemClass,"IPM.Configuration.OWA.ViewStateConfiguration")  
$ivItemView =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(1)  
$ivItemView.Traversal =  [Microsoft.Exchange.WebServices.Data.ItemTraversal]::Associated  
$fiResults = $service.FindItems($folderid,$SfSearchFilter,$ivItemView)  
if($fiResults.Items.Count -eq 0){  
    Write-Host ("No Config Item found, create new Item")  
    $UMConfig = New-Object Microsoft.Exchange.WebServices.Data.UserConfiguration -ArgumentList $service  
    $UMConfig.Save("OWA.ViewStateConfiguration",$folderid)  
}  
else{  
    Write-Host ("Existing Config Item Found");  
}  
#Specify the Root folder where the FAI Item is  
$UsrConfig = [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind($service, "OWA.ViewStateConfiguration", $folderid, [Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All)  
if($UsrConfig.Dictionary.ContainsKey("CalendarViewTypeDesktop")){  
    $UsrConfig.Dictionary["CalendarViewTypeDesktop"] = $CalendarSetting  
}  
else{  
    $UsrConfig.Dictionary.Add("CalendarViewTypeDesktop",$CalendarSetting)  
}
$UsrConfig.Update()  
"Mailbox Updated"

Upvotes: 0

Related Questions