Skip to main content

Using Powershell and WMI to get the MAC address of Remote workstation

·306 words·2 mins
system-administration tech gwmi powershell sysadmin technology wmi
James Pettigrove
Author
James Pettigrove
Cloud Engineer with a focus on Microsoft Azure

It has cropped up from time to time that we need to retrieve information, in this example, the MAC address from remotely located workstations.

While, as it goes in the world of system administration, many ways to skin such a cat, I am going to leverage both the power and versatility of Powershell combined with the vast information warehouse that is WMI (Windows Management Instrumentation).

If your remote computer is a basic configuration then we can start of something simple

(gwmi -ComputerName DNSNAMEORIPADDRESS -Class Win32_NetworkAdapterConfiguration).MACAddress

In the above example, we are using theĀ gwmi cmdlet (alias of Get-WMIObject and are interchangeable), pointing to a remote workstation with -ComputerName switch, filtered out information requested with the -Class switch, wrapping it all in brackets so we can retrieve just the returned Powershell MACAddress property.

Hopefully you will be returned a MAC Address.

However, you may find that if the device has multiple network adapters (such as teredo tunnelling for IPv6, hypervisor bridges, VPN TAPs) you are getting more noise than needed:

Never fear though, we have the technology. If you know more information about the network adapter that you want the MAC address from, we can apply filtering to the original query to bring precious to our result.

If you know the IP address of the network adapter:

(gwmi -ComputerName DNSNAMEORIPADDRESS -Class Win32_NetworkAdapterConfiguration | where {$_.IPAddress -like '192.168.1.6'}).MACAddress

Or if you know the type of network adapter:

(gwmi -ComputerName DNSNAMEORIPADDRESS -Class Win32_NetworkAdapterConfiguration | where {$_.Description -like '*Wireless*'}).MACAddress

There you have it. A quick little one liner that taps into the vast depth of information from the WMI database via Powershell power. It is certainly worth playing around with the properties that the above WMI query can provide in return as the information stored is vast and can lead to endless amounts of utility in your future Powershell magic.

Related

Legacy BIOS and UEFI PXE coexistence
·701 words·4 mins
system-administration tech bios dhcp powershell pxe sccm sysadmin technology uefi windows-server-2012-r2
More and more enterprises are moving towards the modern UEFI devices in their fleet, whether that be desktops, laptops or convertibles.
How to restore a tree of objects from the Active Directory Recycle Bin
·710 words·4 mins
system-administration tech active-directory powershell sysadmin technology
In a previous post I detailed how to setup the Active Directory Recycle Bin and restore single deleted objects back in your Active Directory.
Export users of one AD group and import to another
·196 words·1 min
system-administration tech active-directory powershell sysadmin technology windows
It’s quite common for members of one Active Directory security group to be replicate in another.