【发布时间】:2019-11-27 19:28:04
【问题描述】:
使用 Remove-CalendarEvents -PreviewOnly 时,我可以检索会议事件,甚至可以在测试帐户上删除它们。但是,当我将 -ErrorAction Stop 添加到命令时,我在 AD 帐户上收到了以前没有引发任何错误的新错误。
try\catch 块用于捕获在找不到用户邮箱时引发的错误。这部分有效。但是 try\catch 也捕获了一个新错误:
The "ErrorAction" parameter can't be used on the "Remove-CalendarEvents" cmdlet because it isn't present in the role definition for the current user. Check
the management roles assigned to you, and try again.
At C:\Users\O365ExchangeAdmin\AppData\Local\Temp\tmp_waex0o3a.tea\tmp_waex0o3a.tea.psm1:55507 char:9
+ $steppablePipeline.End()
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [Remove-CalendarEvents], CmdletAccessDeniedException
+ FullyQualifiedErrorId : [Server=CY4PR0101MB2935,RequestId=ba4d86db-d362-432d-9892-4ea92b503356,TimeStamp=7/18/2019 7:18:03 PM] [FailureCategory=Cmdlet-C
mdletAccessDeniedException] 896C46A1,Microsoft.Exchange.Management.StoreTasks.RemoveCalendarEvents
+ PSComputerName : outlook.office365.com
当我删除 -ErrorAction STOP 参数时,命令成功完成,并让我查看会议事件。但是,如果我没有 -ErrorAction STOP,那么当我的脚本在帐户上失败时,我将无法登录,因为它没有邮箱。
Try{
$output = Remove-EXOCalendarEvents -Identity $user.UserPrincipalName -QueryStartDate (Get-Date) -PreviewOnly -CancelOrganizedMeetings -Confirm:$false
}Catch [System.Management.Automation.RemoteException] {
LogWrite "$($user.Name) could not be found, most likely they do not have a mailbox"
}
同时删除 [System.Management.Automation.RemoteException] 不会改变结果。
非常感谢您提供的任何帮助,谢谢!
【问题讨论】:
-
检查是否允许在该命令上使用此参数。使用来自that article的两个cmdlet@
-
查看 ManagementRoleEntry 我无权访问 ErrorAction。直到明天我才能更新这个,但我会再试一次。感谢您的评论,这看起来会奏效!
标签: powershell active-directory office365 exchange-server