Looking for a script to import cvs file that contains Email addresses into a Distribution List

Copper Contributor

I have a simply Excel CVS files that contains the user's last name & email address.  The PowerShell script I'm using is erroring out.  Does anyone have a script that I may be able to used.  FYI:  I'm a newbie to PowerShell

5 Replies
Are you adding the addresses as aliases or members? What's the error?
PS C:\WINDOWS\system32> Import-Csv "c:\thomastest" | foreach{Add-DistributionGroupMember -Identity "firedffastaff" -Member $_.emailaddress}
Import-Csv : Could not find file 'C:\thomastest'.
At line:1 char:1
+ Import-Csv "c:\thomastest" | foreach{Add-DistributionGroupMember -Ide ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Import-Csv], FileNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ImportCsvCommand

Ok easy one to fix. Move the CSV file into a folder called scripts and change the import command to:

Import-Csv "c:\scripts\thomastest.csv"

Running directly from the C: drive can sometimes cause issues, probably not the problem here but good practice to put it into a scripts folder

also I notice you don't have a file extension on your import command. Without the file extension your import-csv will fail

Still not working.  One thing that I'm noticing that may be the problem, is the {Add-DistributionGroupMember command.  I notice when I begin to type in PowerShell ISE the Add-DistributionGroupMember  does not populate like other commands @SeanMcAvinue 

Is this for Exchange on prem or Exchange Online? If on prem you need to run in the Exchange management shell. If online you need to install and connect to the EOL PowerShell module: https://docs.microsoft.com/en-us/powershell/exchange/connect-to-exchange-online-powershell?view=exch...