Search code examples
batch-filepowershellfilesysteminfo

Batch - trying to obtain the detail of systeminfo.exe


Like the results of this..

SYSTEMINFO >> RESULTS.TXT

Systeminfo | find "Network Card"

However, this only captures the first line entry:

Network Card(s):           2 NIC(s) Installed.

What I would really like to see is:

Network Card(s):           2 NIC(s) Installed.
                           [01]: VMware Accelerated AMD PCNet Adapter
                                 Connection Name: Production
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 1.1.1.1
                           [02]: VMware Accelerated AMD PCNet Adapter
                                 Connection Name: Backup
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 2.2.2.2

without having to run the whole systeminfo - can I capture the detail about the Network cards.

Did also try to push this through PowerShell..

& systeminfo.exe | & FIND.exe "Network Card"

And is not working either.. :(


Solution

  • If, like it does for me, Network Card(s): always comes up last in the output of systeminfo, then the following should work for you.

    @echo off
    set s=
    for /f "delims=" %%a in ('systeminfo') do (
        if defined s echo %%a
        for /f %%b in ("%%a") do if "%%b"=="Network" echo %%a & set s=1
    )
    

    Sets s as a switch when it reaches Network Card(s) and outputs everything from there.

    IF the Network Card(s) section doesn't come up last, and you require a more definitive method of getting the network card information, AND you are okay with the CSV formatted output, then this should also work (albeit possibly over complicated):

    @echo off
    setLocal enableDelayedExpansion
    set c=0
    for /f "delims=" %%a in ('systeminfo /FO CSV') do (
        set line=%%a
        set line=!line:,= !
        if "!c!"=="0" for %%b in (!line!) do (
            set /a c+=1
            if "%%~b"=="Network Card(s)" echo %%~b
        ) else for %%c in (!line!) do (
            set /a c-=1
            if "!c!"=="0" echo %%~c
        )
    )