0

像这样的结果。。

系统信息 >> 结果.TXT

系统信息 | 找到“网卡”

但是,这仅捕获第一行条目:

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

我真正想看到的是:

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

无需运行整个系统信息 - 我可以捕获有关网卡的详细信息。

也尝试通过 PowerShell 推动这一点..

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

而且也不工作.. :(

4

4 回答 4

2

如果像对我一样,Network Card(s):总是在 的输出中排在最后systeminfo,那么以下内容应该适合您。

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

当它到达并从那里输出所有内容时设置s为开关。Network Card(s)

如果Network Card(s)部分没有最后出现,并且您需要更明确的方法来获取网卡信息,并且您对 CSV 格式的输出没问题,那么这也应该有效(尽管可能过于复杂):

@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
    )
)
于 2014-03-27T22:18:32.163 回答
1

好吧,即使我刚刚阅读了您试图摆脱 PowerShell 的评论之一,因为我让它工作了,并且它转储了您的示例所拥有的所有信息,我想我还是会发布它...... :)

function Get-NetworkCards {
[cmdletbinding()]
param(
    [parameter(Mandatory=$false)][string]$ComputerName = "LocalHost"
)
    $adapterCfg = ( gwmi -Class Win32_NetworkAdapterConfiguration -ComputerName $ComputerName | Sort-Object Index )

    $adapter = ( gwmi -Class Win32_NetworkAdapter -ComputerName $ComputerName | Sort-Object Index )

    foreach ( $nic in $adapterCfg ) {
        if( $nic.IPEnabled -eq $true ) {
            foreach ( $settings in $adapter ) {
                if( $settings.DeviceID -eq $nic.Index ) {
                    $curr = $settings
                }
            }
            $props = [ordered]@{
                Description = $nic.Description;
                Connection = $curr.NetConnectionID;
                DHCPEnabled = $nic.DHCPEnabled;
                IPAddresses = $nic.IPAddress;
            }

            $Obj = New-Object PSObject -Property $props

            $Obj
        }
    }
}

get-networkcards
于 2014-03-27T22:59:07.123 回答
0

你想在 PowerShell 中做什么 - http://blogs.technet.com/b/heyscriptingguy/archive/2008/09/08/how-do-i-find-information-about-the-network-adapter-cards -on-my-computer.aspx

引用他们的脚本:

Param($computer = "localhost")
function funline ($strIN)
{
 $num = $strIN.length
 for($i=1 ; $i -le $num ; $i++)
  { $funline = $funline + "=" }
    Write-Host -ForegroundColor yellow $strIN 
    Write-Host -ForegroundColor darkYellow $funline
} #end funline

Write-Host -ForegroundColor cyan "Network adapter settings on $computer"
Get-WmiObject -Class win32_NetworkAdapterSetting `
-computername $computer |
Foreach-object `
 {
  If( ([wmi]$_.element).netconnectionstatus -eq 2)
    {
     funline("Adapter: $($_.setting)")
     [wmi]$_.setting
     [wmi]$_.element
    } #end if
 } #end foreach
于 2014-03-27T22:20:14.893 回答
0

在 PowerShell 中进行文本提取的 Systeminfo:

$sys = systeminfo
$start = ($sys | select-string "network card" -SimpleMatch).LineNumber
$sys[($start-1)..($sys.Length-1)] | Out-File RESULTS.TXT

就个人而言,我会使用基于 WMI 的解决方案来获取网络信息。

于 2014-03-27T22:26:05.990 回答