Highlighted
Enthusiast
Enthusiast

Powercli list VM's Portgroups

Jump to solution

i am running vCenter 6.0 and i need to list all of my VM's and their assigned portgroup names via powercli

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

Try like this

Get-VM | Get-NetworkAdapter |

Select @{N='VM';E={$_.Parent.Name}},Name,NetworkName


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
Highlighted
User Moderator
User Moderator

Try like this

Get-VM | Get-NetworkAdapter |

Select @{N='VM';E={$_.Parent.Name}},Name,NetworkName


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
Highlighted
Enthusiast
Enthusiast

your a hero. if you dont mind, can you break down that command for me? so i know exactly whats going on?

what is @{N='VM';E={$_.Parent.Name}},Name,NetworkName calling out exactly?

0 Kudos
Highlighted
User Moderator
User Moderator

Sure, a PowerShell/PowerCLI cmdlet most of the time returns an object.

With the pipeline we can pass the output of one cmdlet (get-VM) as input to another cmdlet (Get-NetworkAdapter).

The resulting object contains a number of properties.

Properties on level 1 (the top-level of the object), can be referred to in a Select-Object with their name (Name,NetworkName).

Properties that are nested can be retrieved by what is called a calculated property.

A calculated property is in fact a hash table with two elements.

The Name (N) part and an Execute (E) part.

In the Execute part we can refer to nested properties (we refer to the object with $_), and we even can do calculations or complete code blocks in there.

I hope that helps


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos