PowerShell Tip – Get List of VMs, MACs, IPs & VHDs

Sometimes I wish you could add more fields to the Hyper-V Console, like MAC Addresses or IP Addresses.

As always, PowerShell to the rescue!

Here’s a quick tip to get a list of virtual machines on a Hyper-V host, along with the MAC addresses and IP addresses.

Here’s the PowerShell code:

Get-VM | Select -ExpandProperty NetworkAdapters | Select VMName, MACAddress, IPAddresses

And here are the results:

PowerShell code to get a list of VMs, MACs & IP Addresses

As you can see from the screen shot above, only *running* VMs show IP addresses.

Want to take it a step further and see which VMs are running Legacy NICs and which VMs have Synthetic NICs? Even virtual switch names?

Easy enough – just lose the second filtering statement.

Get-VM | Select -ExpandProperty NetworkAdapters

PowerShell - show legacy NICs in use on VMs

And this one is for Stanley…

Need a list of which VHDs are attached to which VM?

Get-VM | Get-VMHardDiskDrive | Select-Object -Property VMName, VMID, ComputerName, ControllerType, ControllerNumber, ControllerLocation, Path | Sort-Object -Property VMName | Out-GridView -Title "Virtual Disks"

PowerShell - list of virtual hard disks per VM

Source: PowerShell blog & Keith Mayer’s blog

VN:F [1.9.20_1166]
Rating: 9.7/10 (3 votes cast)