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")
}