I'm trying to capture error from command into variable and to exit script if error occures
Add-DistributionGroupMember -Identity [email protected] -Member `
[email protected] -ErrorAction stop -ErrorVariable MyError `
if ($MyError.Count -gt 0) {`
exit
}
But MyError variable is empty and script continues to run,
if however, specify -ErrorAction SilentlyContinue then script simply continues and error variable is empty
try/catch, so could wrap the call toAdd-DistributionGroupMemberin its own one that exits if it catches anything.