Distribution List

Is there a command that can be added to this that is the user exists then it skips rather bombing out?

Import-CSV 'externalcontacts1.csv' | ForEach {Add-DistributionGroupMember -Identity "Externals" -Member $_.Name}

At the moment I have a spreadsheet with over a 1000 lines and most of them exist thus stopping the script.

Thanks in Advance

John DaviesAsked:
Who is Participating?
Michael PfisterCommented:
Can't test here but I'd try

Import-CSV 'externalcontacts1.csv' | ForEach {Add-DistributionGroupMember -Identity "Externals" -Member $_.Name  -ErrorAction  SilentlyContinue}


Open in new window

John DaviesAuthor Commented:
worked a treat, thank you :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.