更新时的Powershell EWS托管API异常

时间:2013-08-08 22:17:34

标签: .net powershell exchangewebservices ews-managed-api

我正在尝试使用EWS托管API在Exchange上更新某些约会,但在调用update时我一直收到以下错误:

Exception: System.Management.Automation.MethodInvocationException: Exception calling "Update" with "1" argument(s): "Set action is invalid for property." ---> Microsoft.Exchange.WebServices.Data.ServiceResponseException: Set action is invalid 
                    for property.
                       at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()
                       at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalUpdateItems(IEnumerable`1 items, FolderId savedItemsDestinationFolderId, ConflictResolutionMode conflictResolution, Nullable`1 messageDisposition, Nullable`1 
                    sendInvitationsOrCancellationsMode, ServiceErrorHandling errorHandling)
                       at Microsoft.Exchange.WebServices.Data.ExchangeService.UpdateItem(Item item, FolderId savedItemsDestinationFolderId, ConflictResolutionMode conflictResolution, Nullable`1 messageDisposition, Nullable`1 
                    sendInvitationsOrCancellationsMode)
                       at Microsoft.Exchange.WebServices.Data.Item.InternalUpdate(FolderId parentFolderId, ConflictResolutionMode conflictResolutionMode, Nullable`1 messageDisposition, Nullable`1 sendInvitationsOrCancellationsMode)
                       at Microsoft.Exchange.WebServices.Data.Item.Update(ConflictResolutionMode conflictResolutionMode)
                       at CallSite.Target(Closure , CallSite , Object , Object )
                       --- End of inner exception stack trace ---
                       at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
                       at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

这个错误不是很具描述性,所以我真的不知道从哪里开始。我所要做的就是改变一些约会的开始和结束时间。相关代码如下:

$Items = $service.FindAppointments($Calendar.Id,$CalendarView)
foreach($Item in $Items.Items) {
    $Item.Load()
    $Item.StartTimeZone = [System.TimeZoneInfo]::Local
    if ($Item.Subject -eq '01Mar13 15:00 RECD-MTWRF to 30Sep13 17:00'){
        if ($Item.Start.ToString("dddd") -eq 'Friday'){
            $Item.Start = $Item.Start.AddHours(1)
        }
    }
    elseif ($Item.Subject -eq '05Mar13 10:00 RECD-TR to 26Sep13 12:00'){
        if ($Item.Start.ToString("dddd") -eq 'Tuesday'){
            $Item.Start = $Item.Start.AddHours(1)
            $Item.End = $Item.End.AddHours(1)
        }
    }
    try {
        $Item.Update([Microsoft.Exchange.WebServices.Data.ConflictResolutionMode]::AlwaysOverwrite)
    }
    catch {
        $error[0] | fl -force
    }
}

我尝试更改冲突解决模式,并且由于之前的错误而不得不设置Item.StartTimeZone属性。关于什么可能出错的任何想法?提前谢谢。

1 个答案:

答案 0 :(得分:-1)

我试过这个并且适合我:

 $Item.Update("AlwaysOverwrite")