directory - [exchangewebservices] 使用“0”参数调用“更新”的异常:“操作将更改对象类型,这是不允许的。”
问题描述
我的目标是更改公用文件夹文件夹类或创建一个新的公用文件夹作为联系人(使用 new-publicfolder 不可能)。所以我拍了一些 glens ews 的片段。
function FolderIdFromPath{
param (
$FolderPath = "$( throw 'Folder Path is a mandatory Parameter' )"
)
process{
## Find and Bind to Folder based on Path
#Define the path to search should be seperated with \
$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot)
$tfTargetFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
#Split the Search path into an array
$fldArray = $FolderPath.Split("\")
#Loop through the Split Array and do a Search for each level of folder
for ($lint = 1; $lint -lt $fldArray.Length; $lint++) {
#Perform search based on the displayname of each folder level
$fvFolderView = new-object Microsoft.Exchange.WebServices.Data.FolderView(1)
$SfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$fldArray[$lint])
$findFolderResults = $service.FindFolders($tfTargetFolder.Id,$SfSearchFilter,$fvFolderView)
if ($findFolderResults.TotalCount -gt 0){
foreach($folder in $findFolderResults.Folders){
$tfTargetFolder = $folder
}
}
else{
"Error Folder Not Found"
return $null
}
}
if($tfTargetFolder -ne $null){
return $tfTargetFolder.Id.UniqueId.ToString()
}
}
}
#Example use
$fldId = FolderIdFromPath -FolderPath "\my\folder"
$Subfolderid = new-objectMicrosoft.Exchange.WebServices.Data.FolderId($fldId)
$SubFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$SubFolderId)
$subfolder.FolderClass = "IPF.Contact"
$SubFolder.update()
使用“0”参数调用“更新”的异常:“操作将更改对象类型,这是不允许的。”
$SubFolder.update() 使用“0”参数调用“更新”的异常:“操作将更改对象类型,这是不允许的。”
但是,它失败了。这是权限问题还是源代码有问题?
提前致谢。
解决方案
您的代码很难理解,但如果我理解正确,您基本上是在“IPF.Contact”类型的文件夹上执行 GetOrCreate。如果文件夹存在,则尝试更新类型。
正如错误所说,一旦创建对象,您就无法更改对象的基础类型。如果您使用 EWS 将联系人项目作为电子邮件项目读取,然后尝试保存它,您也可能会看到这一点。
您必须创建具有预期类型的文件夹。
推荐阅读
- python - 什么是“TypeError:'dict' 对象不可调用”?
- office365 - 调用 Microsoft Graph API 时出现 WAC 访问令牌错误
- r - 使用部分名称循环读取文件,以使用 fread(cmd=...) 和 rbindlist 在大型组合数据框中创建新变量
- python-3.x - 如何在另一个python文件(python3.7)中使用来自一个python文件的变量数据
- spring - JMS ActiveMQ 消费者,何时确认
- android - 如何从 Activity 调用小部件
- html - 如何删除或隐藏视频控件,不是全部,只有全屏和音量
- oracle - 项目值更改并刷新交互式网格后,IG 的查询不适用于更改的值
- scala - Scalatest 提供 NaN 的匹配器吗?
- linux - 查找行并在末尾附加文本不起作用