List all MAC addresses of all Hyper-V Virtual Machines

You sometimes need to list and get all MAC addresses of all Hyper-V virtual machines in your network. Either for your Hyper-V administration or provisioning if you don’t set an unique MAC address automatically. Here is how to get all those MAC addresses easily with PowerShell.

How to list all MAC address of all VM’s on Hyper-V

This tip shows you how to list MAC addresses on local or remote Hyper-V servers.

A media access control address (MAC address) of a computer is a unique identifier assigned to network interfaces for communications at the data link layer of a network segment. MAC addresses are used as a network address for most IEEE 802 network technologies, including Ethernet and WiFi. Logically, MAC addresses are used in the media access control protocol sublayer of the OSI reference model.

Wikipedia

A MAC address can be assigned manually by you, or automatically by Hyper-V. If you ever need to list all MAC addresses, use the Get-VM and Get-VMNetworkAdapter PowerShell cmdlets as shown in the following example:

On your local Hyper-V host, list the MAC addresses of all virtual machines (VM’s):

Get-VM | Get-VMNetworkAdapter | ft VMName, MacAddress

To list MAC addresses of all virtual machines on all Hyper-V servers, run the following code in your PowerShell console:

$HypervServers = @("HyperV-01", "HyperV-02", "HyperV-03")
foreach ( $HypervServer in $HypervServers ) {
	Get-VM -Computername $HyperVServer | Get-VMNetworkAdapter | ft VMName, MacAddress
}

Or on a per remote Hyper-V server basis, run:

Get-VM -Computername hyper-v_server | Get-VMNetworkAdapter | ft VMName, MacAddress

More neat PowerShell Hyper-V tricks:

Read this too:   Working with file attributes in PowerShell

Did this post helped you solve a problem? Or dit you find it interesting? Support Sysadmins of the North with a direct donation via Paypal of by bank wire transfer IBAN: NL31 ABNA 0432217258 (Jan Reilink). Just $ 5,- or € 5,- is more than enough, thanks!

Support SAOTN.ORG


3,246 views

2 comments

  1. Hi, I have some virtual machines and I don’t know where it was installed, one in particular.

    I searched the servers, but I can’t find that VM.

    I thought the Mac could help me, but no. What makes a VM and its husped team unique?

    I have your IP and your name. What do you recommend to find it?

    1. Hi Tamara, thank you for your question.
      I had to google it a bit for you, because I didn’t had a PowerShell command ready. The first you can try is this example (it’s self explanatory):

      $VM = "my-first-vm"
      $HyperVHosts = @("hyperv-01","hyperv-02","hyperv-03","hyperv-04")
      $VMHost = (Get-VM -ComputerName $HyperVHosts -VMName $VM -ErrorAction SilentlyContinue).ComputerName
      Write-Output "The virtual machine " $VM " is hosted on " $VMHost
      

      However, in my situation, where I used Windows Server 2019'sGet-VMto connect to Server 2012R2 Hyper-V servers, this gave me an error:

      Get-VM : The Hyper-V module used in this Windows PowerShell session cannot be used for remote management of the server
      'hyperv-01'. Load a compatible version of the Hyper-V module, or use Powershell remoting to connect directly to
      the remote server.

      Reading up on Thomas Maurer's PowerShell direct in Hyper-V, I changed my code a bit and successfully tried (it's not perfect!):

      $VM = "my-first-vm"
      $HyperVHosts = @("hyperv-01","hyperv-02","hyperv-03","hyperv-04")
      $VMHost = Invoke-Command -ComputerName $HyperVHosts -ScriptBlock {
      	(Get-VM -VMName $Using:VM -ErrorAction SilentlyContinue).ComputerName
      }
      Write-Output "The virtual machine " $VM " is hosted on " $VMHost

      HTH!

Leave a Reply

Your email address will not be published. Required fields are marked *