【发布时间】:2014-11-05 09:14:24
【问题描述】:
我想用 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 错误消失得如此之快,我看不到它。 大概是语法?
帮助非常感谢! 谢谢。
【问题讨论】:
-
在Powershell中添加
-NoExit参数,这样它就不会退出,你可以阅读错误信息。 -
去哪里?执行此操作时出现错误:找不到与参数名称“noexit”匹配的参数。
-
由于您没有告诉您尝试添加开关的位置,请阅读 Powershell.exe 的 help 并查找正确的语法。
-
我尝试了所有可以想到的地方。在第一个 powershell 之后,在第二个之后,在参数列表中。没有骰子。帮助文档对此没有提供任何帮助。
-
源代码如果我删除了redirectstandardoutput,-noexit 工作正常。但这并不重要..