looking for some pointers with using portqry
and specifically, piping or modifying the output to a CSV.
I have around 20000 servers to check, all with a variance of 3-4 open ports to test and automating portqry
seems the easiest way for me. Can't use 3rd party software as it's an Enterprise firewalled solution I'm testing.
So, I can easily use a FOR
loop to make portqry
run across a txt file line by line which outputs into another txt file.
This is fairly useless at the numbers I'm testing as I need to be able to filter and analyse the data easily.
I then moved onto using a couple of .bats to redirect my output based on the errorlevel of portqry
, ie 0,1,2,3. Which kind of works but is still a pain as I have to hardcode the output for my CSV.
(Excuse the pseudo code)
:TOP
FOR %I in foo.txt, DO 'PORTQRY -n %I -e PORT#
@IF errorlevel =0 '%I,22,LISTENING' >> fooLISTENING.txt
goto END
ELSE
@IF errorlevel =1........
ETC ETC
This is still a bit of a pain as I'd rather see all targets in one place and then filter by listening, etc.
Another issue is that not being able to resolve the host doesn't seem to be an applicable errorlevel number.
At this point I'm starting to look at PowerShell to accomplish this, assign variables at each line then write them into a CSV, but it'd take a while to get that setup in my environment.
Any ideas while I have portqry
though? Or indeed if you know of PS that would do the trick that'd be great too.