Mohammed Hamada
asked on
Adding members to Exchange Distribution Group from a file based on certain criteria
Dear all,
I would like to know how to add a user to an exchange distribution group by matching the user's from a text file. My text file is as following
Group,Email
My current powershell is as following
At the moment this doesn't work and gives the following error
A positional parameter cannot be found that accepts argument '
'.
+ CategoryInfo : InvalidArgument: (:) [Add-DistributionGroupMemb er], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFoun d,Add-Dist ributionGr oupMember
+ PSComputerName
I would appreciate any help to fix this
Thank you
I would like to know how to add a user to an exchange distribution group by matching the user's from a text file. My text file is as following
Group,Email
My current powershell is as following
$Users = Import-Csv "C:\Scripts\Users.csv"
foreach ($User in $Users){
$member = $user.email
group =$user.group
if($group -like "CertainExchangeGroup"){
Add-DistributionGroupMember -Identity "CertainGroup@domain.com" -Member $member{
}
Write-Host $member has been added to $group -ForegroundColor Green}
}
At the moment this doesn't work and gives the following error
A positional parameter cannot be found that accepts argument '
'.
+ CategoryInfo : InvalidArgument: (:) [Add-DistributionGroupMemb
+ FullyQualifiedErrorId : PositionalParameterNotFoun
+ PSComputerName
I would appreciate any help to fix this
Thank you
ASKER
Thanks a lot oBdA that worked as always. I just have another tiny question maybe you could aid me with it.
I want the group to be dynamic not something that I identify there. Is it possible to do so ?
for example
Do you think that would work? matching the existing active directory groups with the one in the csv list and add the users in csv to that particular Exchange Distribution group?
Thanks a lot
I want the group to be dynamic not something that I identify there. Is it possible to do so ?
for example
$Users = Import-Csv "C:\Scripts\Users.csv"
ForEach ($User in $Users) {
$member = $user.email
$group = $user.group
If ($group -like "get-distributiongroup | select name") {
Add-DistributionGroupMember -Identity "$group" -Member $member
Write-Host $member has been added to $group -ForegroundColor Green
}
}
Do you think that would work? matching the existing active directory groups with the one in the csv list and add the users in csv to that particular Exchange Distribution group?
Thanks a lot
Sorry, I can't quite follow what it is you want to do.
You have a csv as input anyway, so why not just adjust the csv to contain only the groups you want to process?
You have a csv as input anyway, so why not just adjust the csv to contain only the groups you want to process?
ASKER
The groups are the same in Active Directory and in the CSV file but Distribution groups are empty and I want to add members according to the csv file.
The csv file is the one that's up to date.
The csv file is the one that's up to date.
So - why the group name check at all? Why not just go through every row and add the user to the respective group?
ASKER
Because the group in CSV doesn't entirely matches the one in AD. The name could be wrong so I want to double check if the group exists and can be matched then add the user.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you as always
ASKER
@oBdA can you please help me with another question? Thank you
https://www.experts-exchange.com/questions/29142549/Changing-Primary-SMTP-address-to-secondary-and-replace-it-with-Name-surname-domain-com.html?
https://www.experts-exchange.com/questions/29142549/Changing-Primary-SMTP-address-to-secondary-and-replace-it-with-Name-surname-domain-com.html?
Indent properly; it's more than eye candy, it helps you identify how deeply you're nested.
Open in new window