Forum Discussion
FarleyT
Oct 06, 2020Copper Contributor
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...
SeanMcAvinue
Oct 06, 2020MVP
Are you adding the addresses as aliases or members? What's the error?
FarleyT
Oct 07, 2020Copper 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
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
- SeanMcAvinueOct 07, 2020MVP
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- FarleyTOct 08, 2020Copper Contributor
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
- SeanMcAvinueOct 08, 2020MVPIs 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=exchange-ps