This will allow you to add in batch users to a distribution list, then first connect to the correct environment as below:
If you are doing this Exchange on-premises then you need this:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://EX01-2016.exoip.local/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session -DisableNameChecking -AllowClobber
If you are doing this in Exchange Online ensure you run this before the script:
Connect-Exchange Online
Then you need to customise the items in bold for your environment:
Import-CSV <FilePath> | foreach {
$UPN=$_.UPN
Write-Progress -Activity "Adding $UPN to group… "
Add-DistributionGroupMember –Identity <GroupUPN> -Member $UPN
If($?)
{
Write-Host $UPN Successfully added -ForegroundColor Green
}
Else
{
Write-Host $UPN - Error occurred –ForegroundColor Red
}
}
The CSV file will need to be in the format as below:
Then your users will be colour coded on the status of the import, green is added and red is failed.....