从bat文件启动PowerShell时出现语法错误

时间:2014-11-05 09:14:25

标签: powershell command-line

我想从bat文件中使用RunAs启动powershell脚本。这很有效。

@echo
SET "InstallerFolder=\\dc01\e\script"

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%InstallerFolder%\Script.ps1""' -Verb RunAs}";

但如果我补充:

-RedirectStandardOutput ""%InstallerFolder%\node.txt"" 

它破了。

所以这条线看起来像这样:

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-RedirectStandardOutput ""%InstallerFolder%\node.txt"" -NoProfile -ExecutionPolicy Bypass -File ""%InstallerFolder%\TSM Client Install Script.ps1""' -Verb RunAs}";

并且在一个PowerShell错误中重新开始,这个错误消失得太快了,我无法看到它。 可能是语法?

非常感谢! 感谢。

1 个答案:

答案 0 :(得分:0)

您收到错误,因为powershell.exe没有-RedirectStandardOuptut参数。 (见Technet)。

此外你的语法也很偏离(但是因为我没有看到任何理由启动powershell再次启动PowerShell,所以我不打算解释语法错误。)

如果要使用cmd中的RunAs,请直接使用它。有关详细信息,请参阅Technet(再次)。

如果您想要追加,可以使用>>>在批处理文件中重定向输出。

相关问题