如何解决Exchange 2016引发创建主类别列表?
当我尝试访问新创建的邮箱上的主类别列表时,我收到“在商店中找不到指定的对象”。 这是通过 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,[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,$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,$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()
}
}
解决方法
类别列表由 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"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。