Getting MAC Addresses
All PowerShell Versions
Getting the MAC of a network adapter is rather simple in PowerShell. Here is one of many ways:
PS> getmac /FO CSV | ConvertFrom-Csv
Physical Address Transport Name
5C-51-4F-62-F2-81 Media disconnected
The challenge might be that the actual column names are localized and can vary from culture to culture. Since the raw information comes from CSV data emitted by getmac.exe, there is a simple trick though: rename the columns to whatever you like by skipping the first line (containing the CSV headers), and then submitting your own unique header names:
getmac.exe /FO CSV |
Select-Object -Skip 1 |
ConvertFrom-Csv -Header MAC, Transport
This will always produce columns named “MAC” and “Transport”.
Of course there are object-oriented approaches, too, like asking the WMI or using special cmdlets in Windows 8.1 or Server 2012/2012 R2. However, we believe the illustrated approach is a fun alternative and shows how to turn raw CSV data into really useful culture-invariant information.
ReTweet this Tip!