PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

image rotation

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.

Latest Scripts

10-01-2014 - Get-ProcessAlt
09-30-2014 - Get-MountedVolumes
09-30-2014 - Get-NetworkCards

As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

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-7D                       \Device\Tcpip_{FF034A81-CBFE-4B11-9D...
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.

Twitter This Tip! ReTweet this Tip!

Copyright 2012 PowerShell.com. All rights reserved.