【问题标题】:Exchange 2016. Provoke creation of Master Category List?Exchange 2016。引发创建主类别列表?
【发布时间】:2021-03-24 14:18:35
【问题描述】:

当我尝试访问新创建的邮箱上的主类别列表时,我得到“在商店中找不到指定的对象”。 这是通过 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()  
    }
}

【问题讨论】:

  • 您能否添加有关情况的更多详细信息,包括预期活动、更多代码和尝试的修复?
  • 我正在尝试扫描大量 (50.000) 邮箱以查找某些类型的敏感数据,当我找到包含它的电子邮件时,我会用一个类别对其进行标记。

标签: powershell exchangewebservices outlook-2016 exchange-server-2016


【解决方案1】:

类别列表由 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"

【讨论】:

  • 感谢您的回答,格伦。但我正在努力让它发挥作用。你有任何可以帮助的代码示例吗?
  • 我已经包含了一个创建视图状态配置项的示例,您应该能够适应它。配置 XML 是更复杂的数据流
  • 谢谢你,格伦。我会试一试。对我来说是新东西,所以如果(当)我卡住了,我可能会回来:-)
猜你喜欢
  • 2010-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-24
  • 2021-05-18
  • 2010-09-14
  • 2017-04-09
  • 1970-01-01
相关资源
最近更新 更多