It is not difficult to get a MAC address in PowerShell. Here's a way:
Copy Code code as follows:
ps> GETMAC/FO CSV | Convertfrom-csv
Physical Address transport Name
---------------- --------------
5c-51-4f-62-f2-7d \device\tcpip_{ff034a81-cbfe-4b11-9d ...
5c-51-4f-62-f2-81 Media Disconnected
The problem we face is to classify data and format it. The unhandled information is from the Getmac.exe output of CSV data, here's a tip: Skip the first line to name your favorite columns (with a CSV header at this point), and you can provide your own unique letterhead:
Copy Code code as follows:
GETMAC.EXE/FO CSV |
Select-object-skip 1 |
Convertfrom-csv-header MAC, Transport
The above will produce a custom letterhead "MAC" and "Transport".
The same is true of object-oriented methods, such as calling special commands in WMI or WIN8.1, or server 2012/2012r2. Anyway, we're explaining an interesting approach that also shows how to translate CSV data into meaningful information.
Supports all PS versions