WMI-Less Network Adapters
We can get a list of network adapters (calling them NICs is a bit outdated: the C in NIC stands for ‘card’, like it’s something you plug into an ISA or PCI slot. These days, it’s almost always built in) from Get-WMI Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration, but per
https://msdn.microsoft.com/en-us/library/aa394216%28v=vs.85%29.aspx
it’s being deprecated. We should now use MSFT_NetAdapter.
Instead, and purely for interest’s sake, let’s call the underlying .NET object instead:
[System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()
It returns a list of all network adapters, and the following
TypeName | Name | MemberType | Definition |
System.Net.NetworkInformation.SystemNetworkInterface | Equals | Method | bool Equals(System.Object obj) |
System.Net.NetworkInformation.SystemNetworkInterface | GetHashCode | Method | int GetHashCode() |
System.Net.NetworkInformation.SystemNetworkInterface | GetIPProperties | Method | System.Net.NetworkInformation.IPInterfaceProperties GetIPProperties() |
System.Net.NetworkInformation.SystemNetworkInterface | GetIPStatistics | Method | System.Net.NetworkInformation.IPInterfaceStatistics GetIPStatistics() |
System.Net.NetworkInformation.SystemNetworkInterface | GetIPv4Statistics | Method | System.Net.NetworkInformation.IPv4InterfaceStatistics GetIPv4Statistics() |
System.Net.NetworkInformation.SystemNetworkInterface | GetPhysicalAddress | Method | System.Net.NetworkInformation.PhysicalAddress GetPhysicalAddress() |
System.Net.NetworkInformation.SystemNetworkInterface | GetType | Method | type GetType() |
System.Net.NetworkInformation.SystemNetworkInterface | Supports | Method | bool Supports(System.Net.NetworkInformation.NetworkInterfaceComponent networkInterfaceComponent) |
System.Net.NetworkInformation.SystemNetworkInterface | ToString | Method | string ToString() |
System.Net.NetworkInformation.SystemNetworkInterface | Description | Property | string Description {get;} |
System.Net.NetworkInformation.SystemNetworkInterface | Id | Property | string Id {get;} |
System.Net.NetworkInformation.SystemNetworkInterface | IsReceiveOnly | Property | bool IsReceiveOnly {get;} |
System.Net.NetworkInformation.SystemNetworkInterface | Name | Property | string Name {get;} |
System.Net.NetworkInformation.SystemNetworkInterface | NetworkInterfaceType | Property | System.Net.NetworkInformation.NetworkInterfaceType NetworkInterfaceType {get;} |
System.Net.NetworkInformation.SystemNetworkInterface | OperationalStatus | Property | System.Net.NetworkInformation.OperationalStatus OperationalStatus {get;} |
System.Net.NetworkInformation.SystemNetworkInterface | Speed | Property | long Speed {get;} |
System.Net.NetworkInformation.SystemNetworkInterface | SupportsMulticast | Property | bool SupportsMulticast {get;} |
Not too shabby, eh? With this, we can get a list of active network adapters
[System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() | ? { $_.OperationalStatus -eq 'Up' }
Wireless network adapters
[System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() | ? { $_.NetworkInterfaceType -match '^Wireless' }
IP addresses
([System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() | ? { $_.NetworkInterfaceType -match '^Wireless' })[0].GetIPProperties().UnicastAddresses
And so on…