How to get powershell to show onlyIP address and interface alias(-name)
I have looked around and have tried to get both the (-interfaceAlias or -Name) of the NIC card to be displayed along with IP address in a table format.
I have tried to use both the Get-NetAdaptor and Get-NetIpaddress commands and I can see that can get either the name or the address but can't work out how to get both at the same time
PS C:\Windows\system32> get-Netadapter | get-Netipaddress | Format-table
ifIndex IPAddress PrefixLength PrefixOrigin SuffixOrigin AddressState PolicyStore
------- --------- ------------ ------------ ------------ ------------ -----------
66 fe80::dc2e:7d51:e01b:6d1b%66 64 WellKnown Link Deprecated ActiveStore
66 169.254.109.27 16 WellKnown Link Tentative ActiveStore
60 fe80::8963:5f37:4a1f:9afc%60 64 WellKnown Link Deprecated ActiveStore
60 172.22.32.1 27 Manual Manual Tentative ActiveStore
60 169.254.154.252 16 WellKnown Link Tentative ActiveStore
25 fe80::a50a:7a1c:3f49:f5df%25 64 WellKnown Link Deprecated ActiveStore
25 169.254.245.223 16 WellKnown Link Tentative ActiveStore
25 169.254.2.1 23 Manual Manual Tentative ActiveStore
25 169.254.1.1 23 Manual Manual Tentative ActiveStore
39 fe80::4c52:9107:fa8c:eb00%39 64 WellKnown Link Deprecated ActiveStore
39 169.254.235.0 16 WellKnown Link Tentative ActiveStore
21 fe80::c059:d2f1:5cec:f910%21 64 WellKnown Link Preferred ActiveStore
21 192.168.3.1 27 Manual Manual Preferred ActiveStore
72 fe80::60e7:8001:9fa7:b080%72 64 WellKnown Link Deprecated ActiveStore
75 fe80::e86f:786b:3a49:ba98%75 64 WellKnown Link Deprecated ActiveStore
72 169.254.176.128 16 WellKnown Link Tentative ActiveStore
72 20.20.20.1 24 Manual Manual Tentative ActiveStore
75 169.254.186.152 16 WellKnown Link Tentative ActiveStore
8 fe80::b4e4:5199:3074:7db%8 64 WellKnown Link Preferred ActiveStore
8 192.168.248.1 23 Manual Manual Preferred ActiveStore
14 fe80::3ceb:65cb:1e1:aa57%14 64 WellKnown Link Preferred ActiveStore
14 192.168.213.1 24 Manual Manual Preferred ActiveStore
4 fe80::5133:490b:9810:6fa%4 64 WellKnown Link Preferred ActiveStoreWhich gives this output fine. I am then wanting to take the below to give me the Netadaptor name
PS C:\Windows\system32> get-Netadapter -name "$localName1"
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
Onboard_A_SCADA_Route1 Intel(R) Ethernet Connection (2) I21... 22 Disconnected 00-30-A7-21-2D-3D 0 bpsWhat I would like to do is either combine or format the output
PS C:\Windows\system32> get-Netadapter -Name "*" | Format-List -property "name", "Ipaddress"
name : TEAM_PCI5 _(B)-PCI5_(C)_61850_Mirror
name : TEAM_PCI4_(C)-PCI4_(D)_OTN_Copadata
name : TEAM-PCI4_(A)-PCI4_(B)-SCADA Mirrorthis only gives me the name not ipaddress
I have also tried
Get-netadpater -name "$localName1" | Get-IPaddressor
Get-netadpater -name "$localName1" | Get-IPaddress |Format-Tableneither display an output.
I have looked online and tried various ways and looked at the Microsoft help but can't see how to combine. Any help greatly appreciated.
21 Answer
You'll need Select-Object to achieve what you want.
The
Select-Objectcmdlet selects specified properties of an object or set of objects. It can also select unique objects, a specified number of objects, or objects in a specified position in an array.
When I want to get specific properties, I always run the command I want with fl * (alias for Format-List *) to get all the properties returned that exist. e.g:
PS C:\Windows\system32> Get-NetAdapter | Get-NetIPAddress | fl *
PrefixOrigin : Dhcp
SuffixOrigin : Dhcp
Type : Unicast
Store : ActiveStore
AddressFamily : IPv4
AddressState : Preferred
ifIndex : 14
Caption :
Description :
ElementName :
InstanceID :
CommunicationStatus :
DetailedStatus :
HealthState :
InstallDate :
Name : ;:8:8:8;>:55;>55;55;
OperatingStatus :
OperationalStatus :
PrimaryStatus :
Status :
StatusDescriptions :
AvailableRequestedStates :
EnabledDefault : 2
EnabledState :
OtherEnabledState :
RequestedState : 12
TimeOfLastStateChange :
TransitioningToState : 12
CreationClassName :
SystemCreationClassName :
SystemName :
NameFormat :
OtherTypeDescription :
ProtocolIFType : 4096
ProtocolType :
Address :
AddressOrigin : 0
AddressType :
IPv4Address : 10.0.0.140
IPv6Address :
IPVersionSupport :
PrefixLength : 24
SubnetMask :
InterfaceAlias : Ethernet
InterfaceIndex : 14
IPAddress : 10.0.0.140
PreferredLifetime : 6.21:47:25
SkipAsSource : False
ValidLifetime : 6.21:47:25
PSComputerName :
CimClass : ROOT/StandardCimv2:MSFT_NetIPAddress
CimInstanceProperties : {Caption, Description, ElementName, InstanceID...}
CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemPropertiesThen I know what properties fit my needs and I can select the ones I want. You can use:
Get-NetAdapter | Get-NetIPAddress | Select-Object InterfaceAlias, IPAddress | Format-TableBut keep in mind that the Format-Table is only used for you to view it. If you need to do something else with the returned properties, omit the Format-Table.