Running PowerShell Scripts on a Remote PC

I installed PS 1.0 on a remote PC (RPC001). I used the Windows Sysinternals tool PSExec.exe to execute the following process on the remote control:

PSExec \\RPC001 -u myID -p myPWD PowerShell C:\script\StartPS.ps1 par1 par2 

Now I can see the PowerShell.exe process running on the remote PC, but actually does nothing, it just hangs there. I tried putting the simple "Write-Output / Host" code in a script line. I run the same script on a remote RTS, it works there.

Not sure if I will skip anything else to run the script using PSExec, or is this a limitation of PSExec.exe. I would like to run a PS script on a remote computer to do something there locally (compress some files locally and delete old files) from my window.

I asked a similar question in Stackoverflow: Run a remote process using powershell . Don suggested I use PSExec. This sounds like an alternative way to solve the problem. However, I cannot get it to work with PowerShell. Any way to get the PS to work on a remote PC?

By the way, I can not use PS 2.0, because my network does not allow me to install Windows XP SP3, which is required for PS 2.0.

+5
source share
4 answers

After further studying the PSExec tool, I think I got a response. I need to add the -i option to tell PSExec to start the process on the remote computer interactively:

 PSExec \\RPC001 -i -u myID -p myPWD PowerShell C:\script\StartPS.ps1 par1 par2 

Without -i, powershell.exe runs on the remote in standby mode. Interestingly, if I run a simple bat (without PS in the bat), it works fine. Maybe this is something special for the PS case? Welcome comments and clarifications.

+6
source

The accepted answer did not work for me, but the following:

 >PsExec.exe \\<SERVER FQDN> -u <DOMAIN\USER> -p <PASSWORD> /accepteula cmd /c "powershell -noninteractive -command gci c:\" 

Example from here

+5
source

Can you try the following?

 psexec \\server cmd /c "echo . | powershell script.ps1" 
+2
source

The accepted answer does not work for me, but it is. Provide a script in the location (c: \ temp_ below on each remote server .server.txt contains a list of IP addresses (one per line).

 psexec @servers.txt -u <username> cmd /c "powershell -noninteractive -file C:\temp\script.ps1" 
0
source

Source: https://habr.com/ru/post/915837/


All Articles