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