2015-03-19 287 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;}"

作品般的魅力耶!^_^