【问题标题】:powershell command invoke-sqlcmd in batch script批处理脚本中的powershell命令invoke-sqlcmd
【发布时间】:2015-03-19 17:11:16
【问题描述】:

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

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

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

谢谢。

【问题讨论】:

    标签: windows powershell batch-file


    【解决方案1】:

    我发现这行得通 :) 在批处理脚本中运行 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;}"

    像魅力一样工作耶! ^_^

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多