Pradeep Shanbhag
Pradeep Shanbhag

Reputation: 477

To get ip address, mac address in powershell

I am trying to fetch the ip address and mac address.Below code is working very fine but not for windows R2 , any one has any suggestions ?

Primary Ip

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

Primary MAC:

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

Upvotes: 1

Views: 19308

Answers (1)

postanote
postanote

Reputation: 16076

I have not had W2K8R2 servers in years, but try it this way...

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

Upvotes: 6

Related Questions