我寫的,可以從PowerShell中,像這樣運行的PowerShell腳本:我已經將其存儲在共享驅動器(S :)上無法從cmd.exe運行powershell腳本?
PS C:> S:\MyScript.ps1 -a "select thing from table where name like 'name'"
,我不能以這種形式無論從PowerShell中運行我的PowerShell腳本或CMD.EXE:
PS C:> powershell S:\MyScript.ps1 -a "select thing from table where name like 'name'"
C:\> powershell S:\MyScript.ps1 -a "select thing from table where name like 'name'"
我也試着運行它繞過executionpolicy:
C:\> powershell -executionpolicy bypass -command S:\MyScript.ps1 -a "select thing from table where name like 'name'"
我也試着用完整的UNC路徑運行(在人以上L的形式):
C:\> powershell \\MyServer\path\to\MyScript.ps1 -a "select thing from table where name like 'name'"
,顯示輸出的唯一方式是,如果我用一個參數,不需要一個字符串傳遞:
C:\> powershell S:\MyScript.ps1 -z
thing
-----
thing1
thing2
thing3
有誰知道這是爲什麼?有什麼方法可以將字符串從cmd.exe傳遞給腳本?
另請注意,powershell.exe有一個參數'-File',它可能比'-command'更適合文件。我不確定腳本參數,因爲它們應該像尼克說的那樣按照字符串分組。試試Nicks解決方案,如果這樣做不起作用,請嘗試'-File'參數而不是'-command'。 – wullxz
-文件似乎工作,謝謝! – EGr
@wullxz把這個作爲一個答案我會投票。 –