我试图提取服务器的NIc卡详细信息,这里是下面的代码,我无法获取输出中显示的$ objitem.netconnectionid的信息,它总是空白,尽管其余部分确实来了。
Write-Host "Network Information" -ForegroundColor Yellow
Write-Host "___________________" -ForegroundColor Yellow
Write-Host
$colItems = get-wmiobject -class "Win32_NetworkAdapterConfiguration" -namespace "root\CIMV2" -computername $compname
foreach ($objItem in $colItems) {
# 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.DNSHostName -ne $NULL) {
# Write to screen
#write-host "Caption: " $objItem.Caption
write-host "NIC Card Name :" $objitem.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
}
}
任何powershell大师都可以帮助我!
感谢, vinith
答案 0 :(得分:2)
NetConnectionID
是Win32_NetworkAdapter
WMI类
这是你的代码做你想要的
Write-Host "Network Information" -ForegroundColor Yellow
Write-Host "___________________" -ForegroundColor Yellow
Write-Host
$colItems = get-wmiobject -class "Win32_NetworkAdapterConfiguration" -namespace "root\CIMV2" -computername $compname
foreach ($objItem in $colItems) {
# 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.DNSHostName -ne $NULL) {
# Write to screen
#write-host "Caption: " $objItem.Caption
#write-host "NIC Card Name :" $objitem.netconnectionid -ForegroundColor Green
$netAdp = get-wmiobject -class "Win32_NetworkAdapter" -Filter "GUID=`'$($objItem.SettingID)`'" -namespace "root\CIMV2" -computername $compname
write-host "NIC Card Name :" $netAdp.NetConnectionID -ForegroundColor Green
write-host "NIC Card Description :" $netAdp.Description -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
}
}
答案 1 :(得分:1)
Win32_NetworkAdapterConfiguration WMI class中没有netconnectionid这样的成员。您从这样的会员那里得到什么样的信息?它可能与另一个名称或成员的成员对象属性一起使用。