【发布时间】:2015-09-26 12:57:23
【问题描述】:
我想通过一个批处理文件运行一些 PowerShell 命令。已经询问了非常相似的question,但我不想从批处理中运行单独的 shell 文件。相反,我想将 PowerShell 命令嵌入到批处理文件中。
当我尝试运行时
powershell -command "&{$var = "something"}"
我收到以下错误:
something :术语“something”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。
在 line:1 char:10
&{$var = 某事}
CategoryInfo : ObjectNotFound: (something:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
但是如果我运行类似的东西
powershell -command "&{echo "something"}"
然后一切都很好:/
我是在做语法错误还是什么?并且请不要给出“不要使用 PowerShell 命令,而是使用批处理命令等...”之类的答案。
提前致谢!
【问题讨论】:
-
你可以在 'something' 或 powershell -command '...' 上使用单引号
-
在您的示例中,您在“某事”周围加上引号,错误表明您没有在实际代码中。
-
另外,请查看this DosTips post 以获取转换器脚本。
标签: windows powershell batch-file command