Search code examples
powershellcsvbatch-fileimport-csv

Powershell import-csv not recognized


I'm trying to make a bat file script that appends the information of a csv to another already existing csv file. I want to use the import-csv command, but I keep getting the error that says:

'import-csv' is not recognized as an internal or external command, operable program or batch file.

I was using Powershell 5.1, so I tried downloading and using Powershell Core 6. That isn't working either. Am I missing a library somewhere?

my code:

import-csv "tinyTesterB.csv"

pause

Solution

  • Inside of a bat file or in the cmd shell, you need to start PowerShell to gain access to its commands. Add the following to your bat file instead:

    For Windows PowerShell:

    Powershell.exe -Command "Import-Csv 'tinyTesterB.csv'"
    

    For PowerShell Core:

    Pwsh.exe -Command "Import-Csv 'tinyTesterB.csv'"