From my script I want to run some command in remote Windows box. So I googled a little and seems the most popular and somehow standard way to do that is to use PowerShell's Invoke-Command
cmdlet which seems to use the same protocol as winrm
and winrs
. So, bellow are commands I've tried to call from my script (actually I've tried lots of other their modifications as well, but IMO these are enough to illustrate the problem):
PowerShell -Command "$encpass=ConvertTo-SecureString -AsPlainText mypass -Force;$cred = New-Object System.Management.Automation.PSCredential -ArgumentList myuser,$encpass; Invoke-Command -ComputerName REMOTE_COMPUTER_NAME -Credential $cred -ScriptBlock {<fullcommand>};"
PowerShell -Command "$encpass=ConvertTo-SecureString -AsPlainText mypass -Force;$cred = New-Object System.Management.Automation.PSCredential -ArgumentList myuser,$encpass; Invoke-Command -ComputerName REMOTE_COMPUTER_NAME -Credential $cred -ScriptBlock {Start-Process -FilePath <fullexepath> -ArgumentList <arguments> -Wait -NoNewWindow};"
PowerShell -Command "$encpass=ConvertTo-SecureString -AsPlainText mypass -Force;$cred = New-Object System.Management.Automation.PSCredential -ArgumentList myuser,$encpass;$session=new-PSSession -ComputerName "REMOTE_COMPUTER_NAME" -Credential $cred; Invoke-Command -Session $session -ScriptBlock {<fullcommand>};"
NOTE: The script is written in perl
, but IMO here the language of the script doesn't matter, so you can suppose that I call the command from batch
script, just note, that as commands should run from a script they should not require any interactive actions.
So, I have several problems with these commands, and need help to figure them out. Here they are:
- Can't run processes of type
configure and run daemon
. Namely if I want to runconfigure_server.pl
on remote box (<fullcommand> = "configure_server.pl <arguments>"
), which should do some stuff, then runserver.exe
, it doesn't work, because as soon asconfigure_server.pl
is done, full remote job is being killed including theserver.exe
which supposed to run as a daemon. (applies to points 1,2,3) - Get wrapped (length of each line is less or equal than 80 chars) standard output and standard error. (applies to point 1,3)
- Don't get standard output and standard error. (applies to point 2)