首页 文章

powershell命令在批处理脚本中调用-cowlcmd

提问于
浏览
0

我有一个powershell命令,我希望在批处理脚本中运行 . 它在powershell窗口中运行良好但我无法在批处理脚本中正确调用它 . powershell命令是这样的:

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

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

谢谢 .

1 回答

  • 0

    我发现有效:)在批处理脚本中运行invoke-sqlcmd:

    我用过这一行:

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

    像魅力雅! ^ _ ^

相关问题