try/catch error trapping Exchange Online

Welcome Forums General PowerShell Q&A try/catch error trapping Exchange Online

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
9 months, 2 weeks ago.

  • Author
    Posts
  • #92420

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 14
    Rank: Member

    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

      Participant
      Points: 0
      Rank: Member

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

The topic ‘try/catch error trapping Exchange Online’ is closed to new replies.