0

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
1
  • 1
    You're trying to run a built-in powershell.exe cmdlet inside cmd.exe Commented Feb 4, 2020 at 22:19

1 Answer 1

5

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'"
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for explaining why this is the case. Do I need to add this prefix to every line? is there a way to make it so that I don't have to add it to every line?
I would create a .ps1 file with the Powershell commands. Then I would call the file Powershell.exe -File 'c:\file.ps1'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.