I was once asked in an interview how to find a MAC address. I answered with getmac which at the time. I thought was the best way of doing this. The guy asking the question obviously wanted ipconfig /all. There is nothing wrong with that but it gives you a lot of unnecessary information if you are only after the MAC address and no way of using this information in a script. It got me thinking about how many ways there are to find a MAC address and which ones are the best ways. Here are 5 that I have came up with.
Get-WmiObject -Class Win32_NetworkAdapterConfiguration
Get-WmiObject -Class win32_networkadapter
My favourite one of these is get-netadapter
I like this one because of the information that it gives. With a simple bit of scripting you could automate this to find the MAC address of every machine in your network showing name and Mac address.
A good this to know when querying with PowerShell is the Select -expandproperty command. If you use this you can narrow you queries down to just the information that is interesting to you.
PS C:\Users\Administrator> get-netadapter | select -ExpandProperty macaddress