首页 > 解决方案 > [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”参数调用“更新”的异常:“操作将更改对象类型,这是不允许的。”

但是,它失败了。这是权限问题还是源代码有问题?

提前致谢。

标签: directoryexchangewebservicespublic

解决方案


您的代码很难理解,但如果我理解正确,您基本上是在“IPF.Contact”类型的文件夹上执行 GetOrCreate。如果文件夹存在,则尝试更新类型。

正如错误所说,一旦创建对象,您就无法更改对象的基础类型。如果您使用 EWS 将联系人项目作为电子邮件项目读取,然后尝试保存它,您也可能会看到这一点。

您必须创建具有预期类型的​​文件夹。


推荐阅读