Monthly Archive


Find the MAC address

One thing that has bugged me for years is having to use the /all parameter with ipconfig to get the MAC address. It also doesn’t work on remote machines. bah humbug.

The MSNdis_EthernetCurrentAddress class in the root\wmi namespace offers a quicker way

function get-macaddress {            
Get-WmiObject -Namespace root\wmi -Class MSNdis_EthernetCurrentAddress `
-ComputerName $computer |            
foreach {            
 $values = @()            
 $_.NdisCurrentAddress |             
 select -ExpandProperty Address |            
 foreach {            
  $values += ([convert]::ToString($_,16)).ToUpper().PadLeft(2,"0")            
 $mac = $values -join "-"            
 New-Object -TypeName PSobject -Property @{            
  Computer = $_.__SERVER            
  Adapter = $_.InstanceName            
  MACAddress = $mac            

Get the WMI objects for MSNdis_EthernetCurrentAddress. For each of them take the NdisCurrentAddress and expand the address property. This gives 6 integer values one for each element of the MAC address. We convert them to hex, convert to upper case and pad a 0 to the left if needed. the MAC address is created by joining those 6 values with a hyphen.

An object is created to output the results

Leave a Reply