0

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

invoke-sqlcmd -inputfile "D:\Reports\sql.sql" -ServerInstance SERVER1 | export-csv "D:\Rpt\historical\sample1.csv" -Force -En UTF8

I hope somebody could help me out. Also, is it possible to include batch variable in replace of the file path for input and output file instead of putting the whole path in powershell command (stil 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! ^_^

Sign up to request clarification or add additional context in comments.

Comments

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.