VMware Cloud Community
Jujo
Enthusiast
Enthusiast
Jump to solution

Creating Tables using Piped Cmdlets

Hello All,

Sorry to do this but I'm in kind of a hurry. I know I need to read the manual and I plan to do so very soon!!

I'm trying to build a table or create output that displays the VM name and the NetworkName. I don't know how to make the output show both. I put together the command below, but this only displays the NetworkName. I've tried various things, but I can't get both items to show up...

Can anyone help me out? Thanks!!!!

Get-Cluster DEV | Get-VM | Get-NetworkAdapter | Select-Object -Property 'NetworkName'

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-Cluster DEV | Get-VM | 
Select Name, @{N="NIC";E={$_ | Get-NetworkAdapter | %{$_.NetworkName}}}

If you have more than 1 NIC on a VM, you can do

Get-Cluster DEV | Get-VM | 
Select Name, @{N="NIC";E={[string]::Join(',',($_ | Get-NetworkAdapter | %{$_.NetworkName}))}}


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

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-Cluster DEV | Get-VM | 
Select Name, @{N="NIC";E={$_ | Get-NetworkAdapter | %{$_.NetworkName}}}

If you have more than 1 NIC on a VM, you can do

Get-Cluster DEV | Get-VM | 
Select Name, @{N="NIC";E={[string]::Join(',',($_ | Get-NetworkAdapter | %{$_.NetworkName}))}}


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

0 Kudos
Jujo
Enthusiast
Enthusiast
Jump to solution

Thanks LucD- I'm getting this returned to me (using PowerGUI):


Missing '=' operator after key in hash literal.At line: 4 char: 26

It's telling me there's something wrong around here "E{$"

0 Kudos
LucD
Leadership
Leadership
Jump to solution

My mistake, typo. It's corrected


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

0 Kudos
Jujo
Enthusiast
Enthusiast
Jump to solution

Ok, this only displays the VM names. Doesn't show the NetworkNames.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I think it's time I call it a day, another typo.

It's corrected now


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

0 Kudos
Jujo
Enthusiast
Enthusiast
Jump to solution

Thanks Luc. That works. Oddly it returns the right data from Powercli, but if I run it in PowerGUI I only get the VM names back. No NetworkNames.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you running the latest version of PowerGui ?


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

0 Kudos
Jujo
Enthusiast
Enthusiast
Jump to solution

Yep- latest PowerGUI, and I just upgraded my PowerCLI too. Same result in PowerGUI. Only VM names.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Must be a PowerGui problem then.

I'll have to admit I'm not well versed in PowerGui, but perhaps you could raise the question in the PowerGui forum.


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

0 Kudos