PSexec copyright output

怎甘沉沦 提交于 2020-12-02 08:25:54

问题


Does anyone know, how to disable "copyright header" from appearing when running PSExec? Everutime I run "./psexec ..." command I see this message:

PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com

It's really annoying and it bloats up output of my script.

Thanks
Matthew


回答1:


There does not appear to be a way to disable it from occurring, but as a workaround you could redirect STDERR which will suppress the output,

psexec \\remotemachine command 2>nul



回答2:


PsExec v2.2 comes with -nobanner option.




回答3:


Or better you can do

set F1=find /v "PsExec v2.11 - Execute processes remotely"
set F2=find /v "Copyright (C) 2001-2014 Mark Russinovich"
set F3=find /v "Sysinternals - www.sysinternals.com"
set FILTER=%F1%^|%F2%^|%F3%

psexec \\remotemachine command 2>&1 | %FILTER%



回答4:


I know this is a rather old question, but since it's tagged PowerShell and there hasn't been a PowerShell specific response, here goes:

I wanted to get the value of the environment variable %SystemRoot% on a remote machine, without enabling WinRM.
My invocation in PowerShell was:
$ret = & PsExec.exe \\RemoteMachine powershell.exe -Command '$env:SYSTEMROOT'

This returned an array of type Object[], with one element per line of output received. Sample output, with corresponding array index:

PS> $ret
(0)
(1) PsExec v2.2 - Execute processes remotely
(2) Copyright (C) 2001-2016 Mark Russinovich
(3) Sysinternals - www.sysinternals.com
(4)
(5) C:\WINDOWS

As you can see my desired output was the 6th value in the returned array.

This does also work with PowerShell scripts or commands that output more than one line, as each printed line is appended to the array as a new element.

With that in mind we can tidy our returned output up with the following:
$ret = $ret[5..($ret.Count - 1)]

This basically just removes the first five elements.

I have not tested this solution with programs other than PowerShell though, so use with care.



来源:https://stackoverflow.com/questions/30193070/psexec-copyright-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!