0

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?

2 Answers 2

2
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. ;)

Sign up to request clarification or add additional context in comments.

Comments

1

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...)

3 Comments

what is your solution to remove the space?
"tokens=3" in place of "tokens=2 delims=:" (3 got lost in transcription)
i used your "tokens=" i still get spacing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.