VMware Cloud Community
halr9000
Commander
Commander

List Virtual Machines and Network Assignments

Continuing my quest to spread PowerShell, my post answers this one:

My problem is, if I want to see what networks the Virtual Machine is connected to, what can I do?? Is there a quick and easy way??

PS > $calcVMHost = @{ N = "VMHostName"; E = { (Get-VMHost -VM $_).Name } }
PS > $calcNetwork = @{ N = "NetworkName"; E = { (Get-NetworkAdapter -VM $_).NetworkName } }

PS > Get-VM | Select-Object Name, $calcVMHost, $calcNetwork

Name                          VMHostName                    NetworkName
----                          ----------                    -----------
vcenter.halr9000.com          192.168.0.51                  VM Network
SDK-XPSP2                     192.168.0.55                  Network0
SDK-RHAS4U4                   192.168.0.55                  Network0
SDK-W2003ENT                  192.168.0.55                  Virtual Machine Network

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

oops - typo

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
4 Replies
admin
Immortal
Immortal

Thanks for the response.

So is there a way that I could install this on Virtual Centre, and use to get a sort of inventory of all my VMs and what network they are connected to??

Reply
0 Kudos
halr9000
Commander
Commander

So is there a way that I could install this on Virtual Centre, and use to get a sort of inventory of all my VMs and what network they are connected to??

You can install it on your VC or any other Windows box. Only requirements are 1) PowerShell and 2) the VI Toolkit.

Then you would login using the Get-ViServer cmdlet, then type in the commands as I gave above.

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
aw443
Contributor
Contributor

Hal,

What if I have some VM's connected to multiple networks?

Reply
0 Kudos
halr9000
Commander
Commander

Sorry, I missed your reply earlier.

This line:

$calcNetwork = @{ N = "NetworkName"; E = { (Get-NetworkAdapter -VM $_).NetworkName } }

Would be changed to something like this:

$calcNetwork = @{ N = "NetworkName"; E = { Get-NetworkAdapter -VM $_ | select NetworkName } }

Then what would happen is that the Select-Object cmdlet would return an array of NetworkName properties. I don't have a 2nd network setup in my lab right now, but it would look something like this:

vmname vmhost {"host network 1", "host network 2"}

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos