Remote Netstat to STDOUT with WMIC?

可紊 提交于 2020-01-06 23:43:17

问题


I would like to use WMIC to retrieve the output of a "netstat" command on a remote computer. The actual execution of the following command executes without error and I see the output popup briefly within a new window:

wmic /node:server1  process call create "netstat.exe -ano"

With that being said, I need to pipe the output of the process window to STDOUT, and have tried:

wmic /node:server1  process call create "netstat.exe -ano > C:\temp\test.txt"

However, that does not work. I have also tried the /output:STDOUT option, however, that only reports the execution of the command:

Executing (Win32_Process)->Create() Method execution successful. Out Parameters: instance of __PARAMETERS {
    ProcessId = 5044;
    ReturnValue = 0; };

Does anyone know how I can go about using WMIC to retrieve the actual output from the new window that was opened in order to process the data?

Thanks in advance!


回答1:


The > symbol behaves as operator of redirection in cmd.exe, not in netstat.exe.
In fact, wmic process call create "netstat.exe -ano > C:\temp\test.txt" is about to run the same as netstat.exe -ano ^> files\nstat.txt (try it from command line).

Next command works (unfortunately, I can't try it with /node:"server1" against a remote computer at the moment):

wmic process call create "cmd /C > C:\temp\test.txt 2>&1 netstat.exe -ano"


来源:https://stackoverflow.com/questions/33107031/remote-netstat-to-stdout-with-wmic

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