I trying to do bulk change of distribution lists, using Powershell script, but didn't made it far.
I importing new addresses and aliases from a .CSV file and seems like this is the issue. Because when I assigning an address and an alias to an exact DL, then it all fine. Or maybe the script written bad.
Error message:
Cannot process argument transformation on parameter 'EmailAddresses'. Cannot convert value "System.Collections.ArrayList" to type "Microsoft.Exchange.Data.ProxyAddressCollection". Error: "The address 'SMTP:@{DisplayName=TEAM_A; [email protected]; [email protected]}.PrimarySmtpAddress' is invalid: The address '@{DisplayName=TEAM_A; [email protected]; [email protected]}.PrimarySmtpAddress' is not a valid SMTP address. Parameter name: address Actual value was @{DisplayName=TEAM_A; [email protected]; [email protected]}.PrimarySmtpAddress." + CategoryInfo : InvalidData: (:) [Set-DistributionGroup], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-DistributionGroup + PSComputerName : outlook.office365.com*
The script:
Connect-ExchangeOnline
$psmtpa = Import-Csv C:\_temp\Excange\PrimarySMTPAddress.csv
ForEach ($name in $psmtpa){
ForEach ($email in $psmtpa){
ForEach ($alias in $psmtpa){
Set-DistributionGroup "$name.DisplayName" -EmailAddresses SMTP:$email.PrimarySmtpAddress,$alias.Alias
}
}
}
And the .CSV look like this:

PS And yeah, I trying to perform it, using PowerShell ISE, instead of writing a one-liner in PowerShell app. Also, I tried WindowsEmailAddress, but powershell don't understand it what is it.
There are a few things to note, first, the double quotes on
"$name.DisplayName"are stringifying the object$nameand appending.DisplayNameto it. Remove them.Second thing to note, on:
If you're looking to add a Primary and Secondary SMTP address, as Mathias pointed out, you should be using:
If instead,
$email.Aliasis actually an Alias, then you should be using:See Subexpression operator
$( )for more info.Lastly, you don't need 3 loops, 1 should be enough to loop over your CSV: