要获取 ip 地址,mac 在 powershell 中的地址

To get ip address, mac address in powershell

我正在尝试获取 IP 地址,mac address.Below 代码运行良好但不适用于 windows R2,有人有什么建议吗?

主 IP

(get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1}).IPAddress | Select-object -index 0

小学MAC:

(Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.ipenabled -EQ $true}).Macaddress | select-object -first 1

我已经很多年没有 W2K8R2 服务器了,但是试试这个...

Get-WmiObject win32_networkadapterconfiguration | 
Select-Object -Property @{
    Name = 'IPAddress'
    Expression = {($PSItem.IPAddress[0])}
},MacAddress | 
Where IPAddress -NE $null

IPAddress      MacAddress       
---------      ----------       
10.0.0.11     50:7B:9D:96:5C:51