Windows Server - parsing interface list from netshell

Asked By Petr Laznovsky
18-Nov-09 05:42 PM
Hi there, I am beginner in the CMD scripting.

I want to get interface list, each iface into each variable. I have two
problems with this. My command is:

for /f "tokens=3,* delims= " %i in ('netsh in sh in') do echo %i %j

I am use local (Czech) language version of WXP and the tranlation of
nesth use two words for loopback ("zpetna smycka" something like "loop
back" with space between those two words). When I try to parse it, there
is problem with delimiter bacause there are two words for loopback in
the column "TYPE", something like this:


Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
Enabled                       Dedicated        dummy
Enabled                       Dedicated        Local Area Connection
Enabled                       Internal         Internal
Enabled                       Loop Back        Loop Back

Second probles is I have no idea how to push ecach line of output (name
of each iface) into separated variable.

Any ideas??

Petr Laznovsky
A0Bluetooth
(1)
SetLocal
(1)
ECtn
(1)
EDti
(1)
Bluetooth
(1)
Povoleno
(1)
Vyhrazen
(1)
Hamachi
(1)
  Pegasus [MVP] replied to Petr Laznovsky
18-Nov-09 06:18 PM
When I run the command
for /f "tokens=3,* delims= " %i in ('netsh in sh in') do echo %i %j
then my console output looks radically different from yours, even when
allowing for linguistic differences. I am therefore unable to give you a
solution that is guaranteed to work for you. And while I appreciate that the
Czech translation of "loopback" generates two words, I do not understand
what you are trying to extract from the console output.

The code below is an example for your second question: How to assign each
line of the screen output to a variable. The text file d:\temp\test.txt
contains the exact console lines that you posted in your note.

@echo off
SetLocal EnableDelayedExpansion
set Line=0
for /F "delims=" %%a in ('type "d:\temp\test.txt"') do (
set /a Line=!Line! + 1
set Var=%%a
echo Line!Line!=!Var!
)
  Tom Lavedas replied to Petr Laznovsky
19-Nov-09 10:37 AM
o
j
esth
=A0 Interface Name
---
=A0 =A0dummy
=A0 =A0Local Area Connection
=A0 =A0 Internal
=A0 =A0Loop Back
e of
ng:
=E1zev rozhran=ED
=A0 =A0Bluetooth Network
=A0 =A0ETH0
=A0 =A0WLAN0
=A0 =A0Bezdr=E1tov=E9 p=F8ipojen=ED k s=EDti 4
=A0 =A0Bezdr=E1tov=E9 p=F8ipojen=ED k s=EDti 2
=A0 =A0Hamachi
=A0 =A0Bezdr=E1tov=E9 p=F8ipojen=ED k s=EDti 3
=A0 =A0 =A0Vnit=F8n=ED
=A0 =A0Zp=ECtn=E1 smy=E8ka
-
Create New Account
help
all, I ve got a small trouble with my script. Here the script: @echo off @SETLOCAL ENABLEEXTENSIONS @SETLOCAL ENABLEDELAYEDEXPANSION FOR / F "tokens = 1-6 " %%i IN ('"WMIC PATH win32_diskquota WHERE (QuotaVolume = 'Win32_LogicalDisk.DeviceID someone will probably propose a much more elegant and maintainable solution. 01. @echo off 02. SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION 03. set Count = 0 04. rem FOR / F "tokens = 1-6 " %%i IN all, I ve got a small trouble with my script. Here the script: @echo off @SETLOCAL ENABLEEXTENSIONS @SETLOCAL ENABLEDELAYEDEXPANSION FOR / F tokens = 1-6
Odd Error Windows Server Hello. . . Here's the script that I'm testing. setlocal enabledelayedexpansion for / f "tokens = 1, 2, 3 delims = / " %%i in ("%date:~4%") do (set yfm Notice that the variable yfm isn't getting updated. C: \ Working> test.bat C: \ Working> setlocal enabledelayedexpansion C: \ Working> for / F "tokens = 1, 2, 3 delims = / " %i in ("03 / 07 / 2007 some other aspect of that larger procedure. I say that for two reasons: first the setlocal statement is not applicable in the example you posted and the second is that the tglbatch / wsh / keywords: Odd, Error description: Hello. . . Here's the script that I'm testing. setlocal enabledelayedexpansion for / f tokens = 1, 2, 3 delims = / %%i in (%date:~4%) do (set yfm
a variable name, as in if !LINECNT! = = TEST mean? Thanks, Alan Windows Server Scripting Discussions SetLocal (1) LINECNT (1) A361 (1) A72e (1) Try these batch files: @echo off set Number L %%a in (1, 1, 10) do ( set Number = %%a echo Number = %Number% ) @echo off SetLocal EnableDelayedExpansion set Number = for / L %%a in (1, 1, 10) do ( set Number = %%a echo