Reputation: 3519
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.. :(
Upvotes: 0
Views: 981
Reputation: 5207
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
)
)
Upvotes: 2
Reputation: 1909
Well, even though I just read in one of the comments you were trying to get away from PowerShell, since I got it working, and it dumps all the info your example had, I figured I'd post it anyway... :)
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
Upvotes: 1
Reputation: 54921
Systeminfo with text-extraction in PowerShell:
$sys = systeminfo
$start = ($sys | select-string "network card" -SimpleMatch).LineNumber
$sys[($start-1)..($sys.Length-1)] | Out-File RESULTS.TXT
Personally, I would have used a WMI-based solution to get the network information.
Upvotes: 0
Reputation: 29033
What you want to do, in 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
Quoting their script:
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
Upvotes: 0