Reputation: 1244
when i execute following command to check the status of a network adapter for Local Area Connection:
netsh interface show interface "Local Area Connection" | find "Administrative state"
it will output the following:
Administrative state: Enabled
or
Administrative state: Disabled
how do i get the enabled or disabled to variable into batch script? I know in linux bash, it will be something like this:
MY_VAR1=$(some_command | grep "someString$" | xargs);
how to do it in windows batch script?
Upvotes: 0
Views: 132
Reputation: 80211
Think again
for /f "tokens=3" %%i in ('netsh interface show interface "Local Area Connection" ^| find "Administrative state"') do set var=%%i
will assign "Enabled" or "Disabled".
Using "tokens=2 deims=:"
will assign
" Enabled "
or " Disabled "
which can be proved by
echo +%var%+
(the +
to show the spaces...)
Upvotes: 1
Reputation: 2688
for /f "tokens=2 delims=:" %%i in ('netsh interface show interface "Local Area Connection" ^| find "Administrative state"') do set var=%%i
use % instead of %% at command-line. ;)
Upvotes: 2