2014-03-27 64 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 - 好點,我錯過了那個小細節...... :) –