简体   繁体   English

PSexec 版权输出

[英]PSexec copyright output

Does anyone know, how to disable "copyright header" from appearing when running PSExec?有谁知道,如何禁用运行 PSExec 时出现的“版权标题”? Everutime I run "./psexec ..." command I see this message:每次我运行“./psexec ...”命令我看到这条消息:

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马修

PsExec v2.2 带有-nobanner选项。

似乎没有办法禁止它发生,但作为一种解决方法,您可以重定向 STDERR,这将抑制输出,

psexec \\remotemachine command 2>nul

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%

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:我知道这是一个相当老的问题,但由于它被标记为PowerShell并且没有特定于PowerShell响应,所以这里是:

I wanted to get the value of the environment variable %SystemRoot% on a remote machine, without enabling WinRM .我想在远程机器上获取环境变量%SystemRoot%的值,而不启用WinRM
My invocation in PowerShell was:我在PowerShell中的调用是:
$ret = & PsExec.exe \\\\RemoteMachine powershell.exe -Command '$env:SYSTEMROOT'

This returned an array of type Object[] , with one element per line of output received.这返回了一个Object[]类型的数组,每行接收到一个元素。 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.如您所见,我想要的输出是返回数组中的第 6 个值。

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.这也适用于输出多行的PowerShell脚本或命令,因为每个打印的行都作为新元素附加到数组中。

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.不过,我尚未使用PowerShell以外的程序测试过此解决方案,因此请谨慎使用。

你试过这个吗:

psexec.exe -nobanner -accepteula

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM