I am trying to create a html report using Creating HTML Reports in PowerShell by Don Jones. What am trying to get to is I would like to get the IP address from Win32_NetworkAdapterConfiguration and NetConnectionID from Win32_NetworkAdapter
Below is the function I am using but the problem is when I output the psobject, NetConnectionID are listed together and not against the IPaddress.
For example
This is how I get
Adaptor Name IP Address Default IPGateway IPSubnet
Local Area Connection Local Area Connection 2 192.168.100.10 192.168.100.1 255.255.255.0
192.168.101.10 192.168.101.1 255.255.255.0
This is how I want
Adaptor Name IP Address Default IPGateway IPSubnet
Local Area Connection 192.168.100.10 192.168.100.1 255.255.255.0
Local Area Connection 2 192.168.101.10 192.168.101.1 255.255.255.0
Could you let me know what am doing wrong here and please help
====================================================================================================================
function Get-InfoNIC {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)][string]$ComputerName
)
$nics = Get-WmiObject -class Win32_NetworkAdapterConfiguration -ComputerName $ComputerName -Filter “IPEnabled=True”
foreach ($nic in $nics) {
$props = @{‘IP Address’=$nic.IPAddress[0];
‘Default IPGateway’=$nic.DefaultIPGateway[0];
‘IPSubnet’=$nic.IPSubnet[0];
‘Adaptor Name’=(Get-WmiObject -class Win32_NetworkAdapter -ComputerName $ComputerName | select -ExpandProperty NetConnectionID)}
New-Object -TypeName PSObject -Property $props
}
}