枚举powershell中所有具有IP和MAC地址的NIC



如何在PowerShell中列出所有具有名称、MAC和IP地址的NIC?

我知道我可以将Get-NetIPAddress和Get-NetAdapter结合起来,但有没有一种简单的方法可以做到这一点,因为这似乎是网络管理中最常见的事情之一。

我还发现Get-NetIPConfiguration-Detailed,但我不明白为什么Get-NetIPConfiguration -Detailed | select InterfaceAlias,NetAdapter.LinkLayerAddress,IPv4Address返回空的MAC地址。

WMI类别Win32_NetworkAdapterConfiguration包含以下信息:

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -computer localhost | Select Description, MACAddress, IPAddress

更多:

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -computer localhost | Select *

在select语句中使用NetIPConfiguration -Detailed时,必须计算子属性LinkLayerAddress:

NetIPConfiguration -Detailed | 
select InterfaceAlias, 
IPv4Address, {$_.NetAdapter.LinkLayerAddress}

上面的方法是有效的,但我们可以给计算出的属性一个名称,如下所示:

NetIPConfiguration -Detailed | 
select InterfaceAlias, 
IPv4Address,
@{
name = 'MacAddress'
expr = {$_.NetAdapter.LinkLayerAddress}
}

最后,作为一句话:

NetIPConfiguration -Detailed | select InterfaceAlias, IPv4Address, @{name = 'MacAddress'; expr = {$_.NetAdapter.LinkLayerAddress}}

最新更新