Add users in bulk under AcceptMessagesOnlyFrom in a DL

I need your help.

I have a very long list of users that need to be added under AcceptMessagesOnlyFrom in  a Distribution List.

Is this piece of code possible in any way to do it in bulk or do I have to do it manually


$Members = Import-CSV C:\temp\allusers.csv

ForEach-Object (Set-DistributionGroup -Identity "DistributionGroup" -AcceptMessagesOnlyFrom $Members)
MargaritaSystems AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeTwo SoftwareSoftware DeveloperCommented:
Hi Margarita,
You might try the following code:
$Members = Import-CSV C:\temp\allusers.csv;
ForEach ($Member in $Members) {Set-DistributionGroup -Identity "DistributionGroup" -AcceptMessagesOnlyFrom @{Add="$Member.SamAccountName"}}

Open in new window

0
Riaz Alexander AnsaryEnterprise Infrastructure Systems EngineerCommented:
I would recommend you create a distribution group add all those users as member and then give the distribution group right to send to the DL by setting it to -AcceptMessagesOnlyFromDLMembers paramter if set-distributiongroup command.
this way if you need to add a user to be able to sent to the DL you can simply add it to that DL that has the members. Cuz the way  you want to do it now, in future if you wanted to add a member it will wipe out everyone and only add that person unless you use add@{} expression. to avoid confusion for end user you hide the distribution list that is for permission from GAL

Please mark as solution if this was helpful
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.

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.