2011-06-17 57 views
1

我試圖提取一個服務器的NIc卡的細節,這裏是下面的代碼,我無法獲得輸出中顯示的$ objitem.netconnectionid的信息,它總是空白,雖然休息的外面確實來了。使用PowerShell gwmi對象提取Nic卡信息!

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

回答

2

NetConnectionIDWin32_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

沒有這樣的一個部件,如使用的Win32_NetworkAdapterConfiguration WMI class netconnectionid。你從這樣一個成員尋找什麼樣的信息?它很可能與另一個名稱或成員的成員對象屬性一起提供。