need2lease
need2lease

Reputation: 136

Remote Netstat to STDOUT with WMIC?

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!

Upvotes: 1

Views: 8311

Answers (1)

JosefZ
JosefZ

Reputation: 30123

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"

Upvotes: 3

Related Questions