1

我正在尝试使用 EWS 托管 API 更新一些交换约会,但在调用更新时我不断收到以下错误:

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 属性。关于什么可能是错误的任何想法?提前致谢。

4

1 回答 1

-1

我已经尝试过了,对我来说效果很好:

 $Item.Update("AlwaysOverwrite")
于 2017-05-23T08:11:31.980 回答