2015-03-19 163 views
0

我有一个powershell命令,我想在批处理脚本中运行。它在PowerShell窗口中运行良好,但我无法在批处理脚本中正确调用它。 PowerShell命令是这样的:powershell命令invoke-sqlcmd批处理脚本

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

我希望有人可以帮助我。另外,是否可以包含批处理变量来代替输入和输出文件的文件路径,而不是将整个路径置于powershell命令中(stil在批处理脚本中运行)?

谢谢。

回答

0

我发现工程:) 运行调用-SQLCMD批处理脚本中:

我必须使用此行:

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

作品般的魅力耶!^_^