0

当我尝试访问新创建的邮箱上的主类别列表时,我得到“在商店中找不到指定的对象”。这是通过 Exchange 2016 上的 Powershell EWS。

如果我打开邮箱并重命名其中一个类别没有问题。猜测 XML 结构仅在需要时创建,因此以前不可用。如何激发主类别列表的创建?

$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)

我得到:

错误:使用“4”参数调用“绑定”的异常:“在商店中找不到指定的对象。,找不到配置对象。名称 = CategoryList。”

---编辑---我一直试图从另一个邮箱复制“模板类别”,但我卡住了。

这是我到目前为止的代码:

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

1 回答 1

0

类别列表由 Outlook 或 OWA 客户端创建,EWS 无法在服务器上自动创建。您可以使用 EWS 自己创建它(或使用模板版本并导入)格式记录在https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxocfg/eb7cac90-6200-4ac3- 8f3c-6c808c681c8b

视图状态示例

$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"

于 2021-03-24T22:57:15.473 回答