0

I have a Powershell command that I want to be run in a batch script. It works well in the Powershell console, but I cannot call it properly in batch script. The Powershell command goes like this:

invoke-sqlcmd -inputfile "D:\T3 Reports\sql.sql" -ServerInstance ISD-DB02 | export-csv "D:\T3RawDataFiles\T3HistoricalRaw\Complaint\samp.csv" -Force -En UTF8

Why doesn't this command work in a batch script?

Also, is it possible to use a batch variable in place of the file path for input and output file instead of putting the whole path in the Powershell command (still run inside in batch script)?

Thanks.

1 Answer 1

0

I have found that works :) to run the invoke-sqlcmd within batch script:

I have use this line:

powershell -Command "& {Add-PSSnapin SqlServerCmdletSnapin100; Add-PSSnapin SqlServerProviderSnapin100; invoke-sqlcmd -inputfile '%sqlPath1%' -ServerInstance %Server% | export-csv '%out_path1%\%out1_fn%' -Force -En UTF8;}"

works like charm yay! ^_^

1
  • yup, that's the typical way to do it :-)
    – megamorf
    Mar 19, 2015 at 9:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .