Getting the IP addresses of running VMs
April 23rd, 2014 by Charlie Russel and tagged Hyper-V, Networking, PowerShell
Ben Armstrong posted a great little tip on his blog the other day. He has a little one-line PowerShell command that gives you a listing of all the running VMs on a host, and the IP addresses being used by each of them.
Get-VM | ?{$_.State -eq "Running"} Get-VMNetworkAdapter | Select VMName, IPAddresses
Add the -ComputerName parameter, with the name of your Hyper-V server in the above, and you’ve got a really useful little script to figure out which VM has an address it shouldn’t. Of course, I just had to tweak it a bit, by changing that last Select to a simple format-table, which allows me to get rid of the unnecessary whitespace with a -auto parameter. Thus:
PSH> Get-VM -computername cpr-asus-lap | ?{$_.State -eq "Running"} | Get-VMNetworkAdapter | ft -auto VMName, IPAddressesVMName IPAddresses------ -----------trey-cdc-05 {192.168.10.5, fe80::812e:a888:ac40:666b, 2001:db8:0:10::5}trey-dc-02 {192.168.10.2, fe80::312c:a27c:c87e:3f98, 2001:db8:0:10::2}trey-wds-11 {192.168.10.11, fe80::4520:ea29:54bb:9b41, 2001:db8:0:10::b}
Thanks, Ben. That’s a useful one!
Posted in Hyper-V, PowerShell | Comments Off on Getting the IP addresses of running VMs