$PSItem Error Handling in Universal Dashboard

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: (:slight_smile: [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.

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.

Adam, thanks for the reply. Sorry, still not familiar enough.

I have a button onclick
Try {

        $Result = Invoke-Command -ScriptBlock { Remove-MailboxFolderPermission -Identity MyUser:\Calendar -User OtherUser -Confirm:$false -SendNotificationToUser $true } -ErrorAction Stop


    } Catch {

        $Result = "Error Message"



Still $Result is Empty.

Ah… managed to get this working:

$Result = Invoke-Command -ScriptBlock { Remove-MailboxFolderPermission -Identity MyUser:\Calendar -User OtherUser -Confirm:$false -SendNotificationToUser $true } -ErrorAction SilentlyContinue -ErrorVariable ProcessError

I can get the error now with this variable.

Is there a way to suppress the red pop-up?

You can turn off that behavior for the dashboard: Dashboards - PowerShell Universal