喜欢这个结果..
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
无需运行整个systeminfo - 我可以捕获有关网卡的详细信息。
还尝试通过PowerShell推送它。
& systeminfo.exe | & FIND.exe "Network Card"
并且不起作用.. :(
答案 0 :(得分: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)
设置为开关。
IF @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
)
)
部分最后没有出现,您需要更明确的方法来获取网卡信息,并且您可以使用CSV格式的输出,那么这也应该有效(尽管可能过于复杂):
{{1}}
答案 1 :(得分: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
答案 2 :(得分: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
答案 3 :(得分:0)
在PowerShell中使用文本提取的Systeminfo:
$sys = systeminfo
$start = ($sys | select-string "network card" -SimpleMatch).LineNumber
$sys[($start-1)..($sys.Length-1)] | Out-File RESULTS.TXT
就个人而言,我会使用基于WMI的解决方案来获取网络信息。