Forum Discussion

FarleyT's avatar
FarleyT
Copper Contributor
Oct 06, 2020

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

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

    • FarleyT's avatar
      FarleyT
      Copper Contributor
      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

Resources