try/catch error trapping Exchange Online

This topic contains 2 replies, has 2 voices, and was last updated by  WakingShell 3 months, 3 weeks ago.

  • Author
    Posts
  • #92420

    WakingShell
    Participant

    Attempting to add users to an Exchange Office 365 group using Add-DistributionGroupMember. The problem is, the error "Couldn't find object" doesn't catch. I've added the -ErrorAction Stop parameter but it is still not catching. What am I missing?

    try
    {
    Add-DistributionGroupMember $DLGroupToAddUsers -Member $UserEmail -ErrorAction Stop
    }
    catch
    {
    $Context.LogMessage("An error occurred when adding the user to $groupName group. Error: " + $_.Exception.Message, "Warning")
    }

  • #92422

    David Schmidtberger
    Participant

    so the root issue i've encountered dealing with exchange, these cmdlets all run remotely, so i have not been able to ever catch remote terminating errors, i've had to settle for running my command, and then performing validation that the change was made as my trying to find errors.

    its driven me nuts over the years but i've come to accept that limitation

    • #92434

      WakingShell
      Participant

      Quite a few of the commands are working – does anyone have a trick to still trap it if it errors?

You must be logged in to reply to this topic.