Home ยป PowerShell ยป PowerShell Get Mac Address

PowerShell Get Mac Address

The command to get the mac address in PowerShell is getmac, Get-WmiObject, or Get-CimInstance. These commands find the mac address on the local and remote computers.

The Get-WmiObject cmdlet in PowerShell uses the win32_networkadapterconfiguration to retrieve the mac address using the macaddress property.

The Get-CmiObject cmdlet in PowerShell is also used to find the mac address. This command uses the win32_networkadapterconfiguration to get the mac address of the adapters.

In this article, we will discuss how to find the mac address using the PowerShell command.

How to Get Mac Address using PowerShell

Use the command-line getmac to get the mac address of the adapters.

getmac

In the above PowerShell script, the command getmac retrieves the mac address for the adapters on the local computer.

The output of the above PowerShell script to obtain the mac address using getmac is:

PowerShell Get Mac Address
PowerShell Get Mac Address

To get the macaddress of the remote computer, use the switch \s computername with the getmac.exe command.

getmac /s CORP-EU-101

The above command will get macaddress on the remote computer.

Find Mac Address on Computer using Get-WmiObject

Use the command Get-WmiObject to get the mac address on a local and remote computer in PowerShell. This command uses the Win32_NetworkAdapterConfiguration class to get adapters and uses the MacAddress property to get the mac address.

# Get mac address on local computer
Get-WmiObject win32_networkadapterconfiguration -Filter "IPEnabled='True'" | select description, macaddress

In the above PowerShell script, the Get-WmiObject cmdlet uses the class win32_networkadapterconfiguration to get the network adapter configuration. This command uses the Filter parameter to get only IPEnabled =True adapters and their macaddress.

The output of the above PowerShell script to retrieve the mac address on the local computer is:

PowerShell Find Mac Address on local computer
PowerShell Find Mac Address on local computer

To get the mac address of the remote computer network adapters, use the Get-WmiObject cmdlet with its ComputerName parameter.

Get-WmiObject win32_networkadapterconfiguration -Filter "IPEnabled='True'" -ComputerName "CORP-EU-101" | select description, macaddress   

Cool Tip: How to use Get-ComputerInfo to get multiple properties of a computer in PowerShell!

Get Mac Address using PowerShell Get-CimInstance

You can get the mac address from the PowerShell command Get-CimInstance on a local computer as well as a remote computer. This command uses the win32_NetWorkAdapterConfiguration class to get all network adapters and uses the macaddress property to obtain the mac address.

# Get mac address on local computer
 Get-CimInstance win32_networkadapterconfiguration -Filter "IPEnabled='True'" | select description, macaddress

The output of the above PowerShell script gets the mac address on the local computer.

PS C:\> Get-CimInstance win32_networkadapterconfiguration -Filter "IPEnabled='True'" | select description, macaddress

description                                                   macaddress
-----------                                                          ----------
Intel(R) Dual Band Wireless-AC 8265       B4-B2-70-D4-A3:A3
Hyper-V Virtual Ethernet Adapter            8D-03-AB-1C-22-65:82


PS C:\>        

To get the mac address on the remote computer, use the remote computername parameter with the Get-CimInstance cmdlet.

# Find the mac address on the remote computer
Get-Ciminstance win32_networkadapterconfiguration -Filter "IPEnabled='True'" -ComputerName "COPR-EU-101" | select description, macaddress     

Cool Tip: How to get the BitLocker recovery key using PowerShell!

Conclusion

I hope the above article on how to get a mac address in PowerShell using the getmac.exe, Get-WmiObject, and Get-CmiInstance cmdlets is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Leave a Comment