Hi, I have a New-UDButton on click which i run the following command
result = Get-MailboxFolderPermission -Identity MyUser:\Calendar -User OtherUser
If the command throws an error, UD takes that error and does a red pop-up. However how do I get this error and handle it myself? I have tried the try {} catch {} but the catch doesn’t seems to execute.
For example
There is no existing permission entry found for user: Erez LastName.
+ CategoryInfo : NotSpecified: ( [Get-MailboxFolderPermission], UserNotFoundInPermissionEntryException
+ FullyQualifiedErrorId : [Server=MEAPR01MB4888,RequestId=78700633-4196-42c0-8c32-4cef180ebb6d,TimeStamp=28/08/2021 9:06:08 AM] [FailureCategory=Cmdlet-UserNotFoundInPermission
EntryException] 8ED3596B,Microsoft.Exchange.Management.StoreTasks.GetMailboxFolderPermission
+ PSComputerName : outlook.office365.com
I’ve spend hours looking for the solution.
Thanks
Erez
UD will show any error (non-terminating or terminating).
You can try to set the ErrorAction to Stop on the cmdlet that is throwing this error. Then you should be able to use a try\catch to catch the exception.