List all VM (guest machine) in VMware with fixed MAC address

I needed a list of all VMs with a Fixed MAC Address running on vSphere (it works for ESX 3.5 as well).

Let’s build up this command from the beginning.  We start with Get-VM to get a hold of all VMs.

Get-VM

This of course will list just any VM.  So we need some filtering. By piping the output of Get-VM into the Get-NetworkAdapter cmdlet, we get some usefull information about the vNICs.

Get-VM | Get-NetworkAdapter


A lot of vNIC info is present, but no details about the MAC Address. We need to dig a little deeper into the vNIC object by using the ExtensionData property. You can access all the properties of the underlying object through this ExtensionData property. And we are interested in the AddressType property:

Get-VM | Get-NetworkAdapter | Foreach-Object {$_.ExtensionData.AddressType}


This will tell you for each vNIC if it’s Assigned (auto generated MAC) or Manual (fixed MAC).
Okay, so now that we know where the info lies, let’s put this in a nice one-liner:

Get-VM | Where-Object {($_ | Get-NetworkAdapter).ExtensionData.AddressType -eq "manual"}


Looking better already.  But what if we want to display the VM Name and the MAC Address as well.

Get-VM | Where-Object {($_ | Get-NetworkAdapter).ExtensionData.AddressType -eq "manual"} | Select-Object -Property Name, PowerState, @{"Name"="MAC";"Expression"={($_ | Get-NetworkAdapter).MacAddress}}

Comments

Popular Posts