我写了一个 powershell 脚本,可以像这样从 powershell 运行:
PS C:> S:\MyScript.ps1 -a "select thing from table where name like 'name'"
我已将它存储在共享驱动器 (S:) 上,但我无法从 powershell 或 cmd.exe 以这种形式运行我的 powershell 脚本:
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'"
我还尝试绕过执行策略运行它:
C:\> powershell -executionpolicy bypass -command S:\MyScript.ps1 -a "select thing from table where name like 'name'"
我还尝试使用完整的 UNC 路径(以上述所有形式)运行它:
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
更好。我不确定脚本参数,因为它们应该像 Nick 所说的那样分组在一个字符串中。只需尝试 Nicks 解决方案,如果这不起作用,请尝试 -File
参数而不是 -command
。
关于string - 无法从 cmd.exe 运行 powershell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14407998/