VMware Cloud Community
DZ1
Hot Shot
Hot Shot
Jump to solution

Just trying to increase my knowledge

First of all, thanks to all the members that contribute, it has helped me tremendously in my knowledge of powershell.  Now, on to my question.  I'm just curious, I ran this Get-VMhost | Group Version..I know what it does, but I'm curious about formatting. 

Get-VMhost | Group Version | Gm shows this as a GroupInfo object, but if I save it to a variable, then it shows it as FormatStartData, GroupStartData, FormatEntryData, GroupEndData, and so on.

The actual names of the ESXi hosts in Group gets cut off, and I thought it was some type of array, but it's not.  My long post for a short question is...how do I how all the names of the Hosts in the Group section.  To get around this, I just used a foreach, and I had it display the version and the ESXi host, this is more of a learning question, rather than a "I need this for work" question.  Thanks. 

Oh, I tried to format-list, format-table -autosize, I looked back on some help I had for -join, but I don't see how I could, or if it could be applied here. 

Count  Name                    Group                                                                                                                                                
-----      ----                        -----                                                                                                                                                
   16    5.0.0                     {name-esx..local, Name-esx..local, Name-esx..local, Name-esx..local...}                                
    7     4.1.0                     {Name-esx.., name-esx.., name-esx..local, name-esx..local...}
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That's the PowerShell output routine that is doing that.

It tries to place as much information as possible on the console, taking into account the linewidth of the console.

ONe way of seeing the complete values is to go for the Format-List cmdlet

Something like this

Get-VMHost | Group-Object version | Select Name,Count,@{N="Hosts";E={
  [string]::Join(',',($_.Group | Select -ExpandProperty Name))
}} | fl

It uses the [string]::Join function to place all the hostnames in 1 string.


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

That's the PowerShell output routine that is doing that.

It tries to place as much information as possible on the console, taking into account the linewidth of the console.

ONe way of seeing the complete values is to go for the Format-List cmdlet

Something like this

Get-VMHost | Group-Object version | Select Name,Count,@{N="Hosts";E={
  [string]::Join(',',($_.Group | Select -ExpandProperty Name))
}} | fl

It uses the [string]::Join function to place all the hostnames in 1 string.


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

0 Kudos
DZ1
Hot Shot
Hot Shot
Jump to solution

Wow, you always come through, you have powershell running through your veins.  Thank you. 

0 Kudos
DZ1
Hot Shot
Hot Shot
Jump to solution

Also, what is nice, is that I understand exactly why that worked (would have taken forever on my own, however), and more than anything, I want that knowledge.  I see that a lot of my issues involve using -join, [string]::join, and Select-Object -ExpandProperty.  I going to have to read up on those more.

Thanks again Smiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley Happy

0 Kudos
DZ1
Hot Shot
Hot Shot
Jump to solution

Thanks again for your help, I was playing around with join and split, and I want to run something by you.  The line you posted worked, but I was trying to join and then split the output, just to see how it's done.

Your line produces this

Get-VMHost | Group-Object version | Select Name,Count,@{N="Hosts";E={
  [string]::Join(',',($_.Group | Select -ExpandProperty Name))
}} | fl

Count : 7
Name  : 4.1.0
Hosts : Host, Host, Host, Host, host,
           Host, Host, Host, Host
So, it shows all the hosts, and that's great..but what if I want the Group section for Hosts to be vertical..like:
Count : 7
Name  : 4.1.0
Hosts :  Host
            Host
            Host
            Host
            Host

I tried some things, like

Get-VMHost | Group Version | Select Name, Count, @{ N='Hosts'; E= { [string]::Join(', ',($_.Group | Select -ExpandProperty Name) ).Split(',') } } | fl

Trying to practice, I played around with it on a process

ps | group processname | Select Count, Name, @{ N='Process'; E={ [string]::Join(',',($_.Group | Select -ExpandProperty Name) ) -split ',',($_.group | Select -ExpandProperty Name)} } | fl

I also tried using the Name "Process", since that's what the hash table has, I tried a few different things.

How could that be acomplished?  Thanks in advance.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

What you want to is in fact nicely formatting the output on your screen.

That is also possible, but that is not really using PowerShell at it's best 😉

Get-VMHost | Group-Object version | %{
  "Count: " + [string]$_.Count
  "Name:  " + $_.Name
  $_.Group | %{     "`t$_.Name"
  } }


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

DZ1
Hot Shot
Hot Shot
Jump to solution

Thanks, you always deliver.  I just want to look at different ways of using Powershell, I want to give myself ideas.  Many Many Thanks!

0 Kudos