Get output from WMIC via a for loop
Posted: 09 Mar 2015 11:26
Normally when I need to get the output of a WMIC query without the extra LF, I just pass it through a second For sub with %* and everything works as expected. This time though, it isn't working. I'm trying to list the available, working NICs and get the IPaddress, subnetmask and gateway for them. This is what I've tried:
And
But neither work and I'm not sure why. Any clues? I'm hoping it's something simple.
Code: Select all
::@echo off
setlocal
Call :wmic nicconfig where "IPConnectionMetric!=''" get ipaddress,macaddress,defaultipgateway,caption /format:list
exit /b
:wmic
for /f "delims=" %%A in ('"wmic %*"') do for /f "delims=" %%B in ("%%A") do echo %%B
exit /b
And
Code: Select all
::@echo off
setlocal
Call :wmic nicconfig where "IPConnectionMetric>0" get ipaddress,macaddress,defaultipgateway,caption /format:list
exit /b
:wmic
for /f "delims=" %%A in ('"wmic %*"') do for /f "delims=" %%B in ("%%A") do echo %%B
exit /b
But neither work and I'm not sure why. Any clues? I'm hoping it's something simple.