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.
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
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
Wow, you always come through, you have powershell running through your veins. Thank you.
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
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
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.
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
Thanks, you always deliver. I just want to look at different ways of using Powershell, I want to give myself ideas. Many Many Thanks!