Powershell script help needed for displaying network interfaces
I have a script [below] that returns information about the network interfaces in .csv
format, but I also need the InterfaceAlias
of each adapter returned; unfortunately, I cannot get get-wmiobject Win32_NetworkAdapterConfiguration
to return such a value.
Can someone help?
$computer = "myserver.myserver.com"
get-wmiobject Win32_NetworkAdapterConfiguration -filter "IPEnabled=TRUE" -computername $computer | foreach-object {
$_ | select-object `
@{Name="ComputerName"; Expression={$_.__SERVER}},
@{Name="MACAddress"; Expression={$_.MACAddress}},
@{Name="IPAddress"; Expression={$_.IPAddress[0]}},
@{Name="Caption"; Expression={$_.Caption}},
@{Name="IPSubnet"; Expression={$_.IPSubnet[0]}},
@{Name="DefaultIPGateway"; Expression={$_.DefaultIPGateway[0]}}
}| Export-Csv -path "C:\ip_addresses_PG.csv"```
You could use Get-NetIPInterface with the -InterfaceIndex
parameter to return the InterfaceAlias
property value and put that into an expression of the select statement.
If that doesn't suffice, you could use Get-NetAdapter with the -IncludeHidden
parameter and a where
filter to match the index value and put that into an expression of the select statement.
Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled=TRUE" | foreach-object {
$_ | select-object `
@{Name="ComputerName"; Expression={$_.__SERVER}},
@{Name="MACAddress"; Expression={$_.MACAddress}},
@{Name="IPAddress"; Expression={$_.IPAddress[0]}},
@{Name="Caption"; Expression={$_.Caption}},
@{Name="IPSubnet"; Expression={$_.IPSubnet[0]}},
@{Name="Alias1"; Expression={(Get-NetIPInterface -InterfaceIndex $_.InterfaceIndex).InterfaceAlias[0]}},
@{Name="Alias2"; Expression={(Get-NetAdapter -IncludeHidden | where ifIndex -eq $_.InterfaceIndex).ifAlias}},
@{Name="DefaultIPGateway"; Expression={$_.DefaultIPGateway[0]}}
}
Supporting Resources
-
Get-NetIPInterface
-
Get-NetAdapter
-IncludeHidden
Indicates that the cmdlet includes both visible and hidden network adapters in the operation. By default only visible network adapters are included. If a wildcard character is used in identifying a network adapter and this parameter has been specified, then the wildcard string is matched against both hidden and visible network adapters.
-
Where-Object