Aug 18 2011 1:01PM GMT
Posted by: Richard Siddaway
Network, PowerShell v2, WMI
Find the MAC address
Posted by: Richard Siddaway
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 { param( [string]$computer="." ) 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




