2014-03-27 34 views
0

喜欢这个结果的详细..批次 - 试图获得systeminfo.exe

SYSTEMINFO >> RESULTS.TXT

SYSTEMINFO |找到“网卡”

然而,这仅捕获的第一行输入:

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" 

而且不工作或者.. :(

回答

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)并输出从那里的一切。

IFNetwork 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 
    ) 
) 
+0

这真棒!我喜欢它,并且工作得很好。我真的试图摆脱使用PowerShell。 – Leptonator

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 
0

SYSTEMINFO在PowerShell中的文本提取:

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

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

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 
+0

我很感谢您的协助。我可以运行PowerShell和Batch ..我可以运行VBS,但必须进行代码签名。只是试图摆脱必须运行许多技术..再次感谢! – Leptonator

+1

在附注中,你实际上并没有返回systeminfo所做的一切。 SystemInfo踢回物理适配器。如果你用这个代替整个ForEach循环,它会修正它:'ForEach($ adapter in $ adapter){If($ NIC.PhysicalAdapter){$ Curr = $ adapterCfg |?{$ _。Index -eq $ NIC.DeviceID} ; [pscustomobject] @ {Description = $ curr.Description; Connection = $ NIC.NetConnectionID; DHCPEnabled = $ Curr.DHCPEnabled; IPAddresses = $ Curr。IPAddress}}}' – TheMadTechnician

+0

@TheMadTechnician - 好点,我错过了那个小细节...... :) –