Reputation: 43
i am trying to add a user to Distribution group using Power Shell. But i want to check if user is already a member of the Distribution List and if he is the member of the Distribution List i want to store the result in a variable so that i can make further decision. So far i have tried the below script but it gives the list of all the member. Please help me with this.
$dl=Get-DistributionGroupMember -Identity DL_Name
if i can store a result in some variable then further logic can be made.
Upvotes: 1
Views: 3390
Reputation: 470
If I understand correctly and the code you are currently using provides you with a list of all members then all you need to do is check to see if that list contains the member you want to add before adding.
if ($dl -notcontains $userToAdd) {
Add-DistributionGroupMember -Identity DL_Name -Member $userToAdd
}
Upvotes: 1