Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在vbscript中将变量传递给psexec powershell命令_Powershell_Command Line_Vbscript_Psexec - Fatal编程技术网

在vbscript中将变量传递给psexec powershell命令

在vbscript中将变量传递给psexec powershell命令,powershell,command-line,vbscript,psexec,Powershell,Command Line,Vbscript,Psexec,我正在尝试将用户输入的计算机名传递给psexec命令。我什么都试过了。我知道该命令是有效的,因为如果我通过手动输入计算机名来运行文件,则会成功。我需要将strComputer变量放入\strComputer psexec命令中。提前谢谢 Set objShell = CreateObject("Wscript.shell") Dim strComputer strComputer=InputBox("Run app on remote computer",,"Type name here &

我正在尝试将用户输入的计算机名传递给psexec命令。我什么都试过了。我知道该命令是有效的,因为如果我通过手动输入计算机名来运行文件,则会成功。我需要将strComputer变量放入\strComputer psexec命令中。提前谢谢

Set objShell = CreateObject("Wscript.shell")

Dim strComputer

strComputer=InputBox("Run app on remote computer",,"Type name here & click OK")

objShell.run("powershell psexec.exe -i -s \\strComputer \\domain.com\folder\app.exe domain.com")

MsgBox("Scan complete")

为什么不为此使用PowerShell脚本

Contents of myscript.ps1
------------------------
$computerName = Read-Host "Enter name of remote computer"
psexec \\$computerName -i -s \\domain.com\folder\app.exe domain.com
"Scan complete"

究竟为什么要将Vbs和Powershell与Cli工具混合使用?我猜是因为我没有这方面的经验。在远程机器上执行psexec的最佳解决方案是什么?在添加powershell之前,我甚至无法运行psexec。谢谢@Keith。我试着运行,但我不认为GP会允许它。我刚收到一些红色文本,PS窗口就消失了。由于某种原因,如果我使用原始帖子中的方式,它将运行。@Kevin_A这是登录脚本吗?此外,当您使用powershell.exe运行此程序时,可能需要使用参数
-executionpolicy Unrestricted
。不,不是登录脚本。我只想在远程机器上手动运行一个LAN监控应用程序。我可以像上面键入的那样运行它,只需输入实际的计算机名而不是\\computerName。我不明白。Get ExecutionPolicy返回Restricted,但我无法更改它。我在上阅读了页面并试图更改策略,但不允许我更改注册表项。我不明白如何在objShell.run()方法中使用powershell命令运行它。这没有意义。只是一个错误,说明此系统上禁用了脚本的执行,但我可以通过.vbs文件运行powershell…在vbs文件中,从技术上讲,您没有运行powershell脚本,即.ps1文件。即使执行策略设置为受限,用户仍可以在PowerShell控制台中交互执行命令。您的VBS脚本或多或少在该模式下运行。当您运行
Set ExecutionPolicy RemoteSigned
时,请确保您是从提升的/管理控制台运行它。