微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NIC卡信息保持循环

我试图提取NIc卡信息为一个服务器使用双循环,即时通讯面临一个问题,因为如果有5个NIC卡循环运行,并提供相同的出5倍,在NIc卡信息不断循环,任何方式来打破输出? 它提供了5个nic卡的信息,并使其出来for循环。

$colItems1 = get-wmiobject -class "Win32_NetworkAdapter" -namespace "rootCIMV2" -computername localhost $colItems = get-wmiobject -class "Win32_NetworkAdapterconfiguration" -namespace "rootCIMV2" -computername localhost foreach ($objitem in $colItems) { foreach ($objItem1 in $colItems1) { # A test is needed here as the loop will find a number of virtual network configurations with no "Hostname" # So if the "Hostname" does not exist,do NOT display it! if ($objItem.ipenabled -eq "true" ) { if ($objitem1.netconnectionid){ # Write to screen #write-host "Caption: " $objItem.Caption write-host "NIC Card Name :" $objitem1.netconnectionid -ForegroundColor Green Write-Host "DHCP Enabled :" $objItem.DHCPEnabled -ForegroundColor green Write-Host "IP Address :" $objItem.IPAddress -ForegroundColor green Write-Host "subnet Mask :" $objItem.IPsubnet -ForegroundColor green Write-Host "Gateway :" $objItem.DefaultIPGateway -ForegroundColor green #Write-Host "MAC Address :"$ojbItem.MACAddress -ForegroundColor green #write-host "Default IP Gateway: " $objItem.DefaultIPGateway #write-host "Description: " $objItem.Description write-host "DHCP Server :" $objItem.DHcpserver -ForegroundColor green write-host "DNS Domain :" $objItem.DNSDomain -ForegroundColor green write-host "DNS Domain Suffix Search Order:" $objItem.DNSDomainSuffixSearchOrder -ForegroundColor green write-host "DNS Server Search Order :" $objItem.DNSServerSearchOrder -ForegroundColor green write-host #write-host "Index: " $objItem.Index # Create HTML Output } } } }

请求一个人请帮助我一样。

awk命令结果放入数组

copy_to_user包含数组(指针)的结构

将单个string移到上一行

将值插入数组并显示,nasm

数组长度在openjdk中改变

嵌套的循环导致重复的输出。 尝试:

$colItems1 = get-wmiobject -class "Win32_NetworkAdapter" -namespace "rootCIMV2" -computername localhost $colItems = get-wmiobject -class "Win32_NetworkAdapterconfiguration" -namespace "rootCIMV2" -computername localhost foreach ($objitem in $colItems) { # Match the current $objItem with the correct $ColItems1 element. $objItem1 = $colItems1|?{$_.Caption -eq $objItem.Caption} # A test is needed here as the loop will find a number of virtual network configurations with no "Hostname" # So if the "Hostname" does not exist,do NOT display it! if ($objItem.ipenabled -eq "true" -and $objitem1.netconnectionid) { # Write to screen #write-host "Caption: " $objItem.Caption write-host "NIC Card Name :" $objitem1.netconnectionid -ForegroundColor Green Write-Host "DHCP Enabled :" $objItem.DHCPEnabled -ForegroundColor green Write-Host "IP Address :" $objItem.IPAddress -ForegroundColor green Write-Host "subnet Mask :" $objItem.IPsubnet -ForegroundColor green Write-Host "Gateway :" $objItem.DefaultIPGateway -ForegroundColor green write-host "DHCP server :" $objItem.DHcpserver -ForegroundColor green write-host "DNS Domain :" $objItem.DNSDomain -ForegroundColor green write-host "DNS Domain Suffix Search Order:" $objItem.DNSDomainSuffixSearchOrder -ForegroundColor green write-host "DNS server Search Order :" $objItem.DNSserverSearchOrder -ForegroundColor green write-host } }

行$objItem1 = $colItems1|?{$_.Caption -eq $objItem.Caption}将匹配两个集合中的NIC; 在你的例子中,你将Win32_NetworkAdapter中的每个NIC与Win32_NetworkAdapter配置中的每个NIC相结合。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐