Hi All
i have a distribution list and i want to add 5000 users to it. i have a csv file in the below format.
users
user1@contoso.com
user2@contoso.com
Some users will not get added since their email addresses are wrong as my csv file is not accurate. i want to get those users which were not added to the DL and those users which are added to the DL as a csv file.
i want to try something like the below but i am not sure.
$users = Import-CSV c:\temp\data.csv
$mbxs = Get-Mailbox -ResultSize unlimited
$output1 = foreach($mbx in $mbxs)
{
Get-Mailbox -Identity $mbx.Name
}
$output2 = foreach($user in $users)
{
if($output1.EmailAddresses -contains $user.user)
{
Add-DistributionGroupMember -Identity d1@contoso.com -Member $user.user
Write-Host "Adding $user.user to Group" -ForegroundColor Green
}
else
{
Write-Host "Failed Adding $user.user to Group" -ForegroundColor Red
}
}
Get-DistributionGroupMember -Identity d1@contoso.com | Export-csv c:\temp\op.csv