在远程 PC 上运行 PowerShell 脚本 [英] Run PowerShell scripts on remote PC
问题描述
我已在远程 PC (RPC001) 上安装了 PS 1.0.我使用了 Windows Sysinternals工具 PSExec.exe 在远程执行以下过程:
I have installed PS 1.0 on a remote PC(RPC001). I used Windows Sysinternals tool PSExec.exe to execute the following process on the remote:
PSExec \\RPC001 -u myID -p myPWD PowerShell C:\script\StartPS.ps1 par1 par2
之后我可以看到 PowerShell.exe 进程在远程 PC 上运行,但它实际上什么也没做,只是挂在那里.我试图在脚本中放入一个简单的写入输出/主机"代码.我通过 RTS 在遥控器上运行相同的脚本,它在那里工作.
I can see the PowerShell.exe process running on the remote PC afterwards, but it is actually doing nothing, just hanging there. I tried to put a simple code of "Write-Output/Host" a string in the script. I run the same script on the remote by RTS, it works there.
不确定我是否错过了使用 PSExec 运行脚本的其他任何东西,或者是 PSExec.exe 限制.我想在远程启动 PS 脚本,以便从我的盒子中在本地执行某些操作(在本地压缩一些文件并删除旧文件).
Not sure if I miss anything else to run the script by using PSExec, or it is PSExec.exe limitation. I would like to start a PS script on remote to do something there locally (compress some files locally and remove old files) from my box.
我在 Stackoverflow 中问了一个类似的问题:通过 powershell 运行远程进程一>.Don 建议我使用 PSExec.这听起来像是解决问题的另一种方法.但是,我无法在 PowerShell 中使用它.有什么方法可以让 PS 在远程 PC 上工作?
I asked a similar question in Stackoverflow: Run remote process by powershell. Don suggested me to use PSExec. It sounds like an alternative way to solve the issue. However, I cannot get it working with PowerShell. Any way to get PS working on remote PC?
顺便说一下,我无法使用 PS 2.0,因为我的网络不允许我安装 PS 2.0 所需的 Windows XP SP3.
By the way, I cannot use PS 2.0 since my network does not allow me to install Windows XP SP3, which is required for PS 2.0.
推荐答案
经过对 PSExec 工具的进一步调查,我想我得到了答案.我需要添加 -i 选项来告诉 PSExec 以交互模式在远程启动进程:
After further investigating on PSExec tool, I think I got the answer. I need to add -i option to tell PSExec to launch process on remote in interactive mode:
PSExec \\RPC001 -i -u myID -p myPWD PowerShell C:\script\StartPS.ps1 par1 par2
如果没有 -i,powershell.exe 以等待模式在远程运行.有趣的一点是,如果我运行一个简单的 bat(bat 中没有 PS),它可以正常工作.也许这对 PS 盒来说很特别?欢迎评论和解释.
Without -i, powershell.exe is running on the remote in waiting mode. Interesting point is that if I run a simple bat (without PS in bat), it works fine. Maybe this is something special for PS case? Welcome comments and explanations.
这篇关于在远程 PC 上运行 PowerShell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!