VMware Cloud Community
zhornsby
Enthusiast
Enthusiast
Jump to solution

Powercli list VM's Portgroups

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
LucD
Leadership
Leadership
Jump to solution

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
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM | Get-NetworkAdapter |

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


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

0 Kudos
zhornsby
Enthusiast
Enthusiast
Jump to solution

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
LucD
Leadership
Leadership
Jump to solution

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