scotty_p
Enthusiast
Enthusiast

Find Cluster name in get-view

Jump to solution

Hello,

I'm trying to make a list of cluster names and number of hosts using get-view, but I'm having trouble figuring out how I can get the cluster name to align with the number of hosts.

I'm starting with this...

$cluster=get-cluster | get-view

then I can pull the number of hosts per cluster, using

$cluster.summary.numhosts

But, it just shows a column of numbers. How can I also pull the cluster name next to that?

Thanks,

Scott

1 Solution

Accepted Solutions
vbrad6841
Enthusiast
Enthusiast

This should write what you're looking for to the screen...

$clusters = Get-Cluster | Get-View

foreach($cluster in $clusters){

$cluster.name

$cluster.summary.numhosts

}

You should be able to manipulate that to export to a file if necessary.

Blog: https://lowercasevblog.wordpress.com/

View solution in original post

0 Kudos
6 Replies
vbrad6841
Enthusiast
Enthusiast

This should write what you're looking for to the screen...

$clusters = Get-Cluster | Get-View

foreach($cluster in $clusters){

$cluster.name

$cluster.summary.numhosts

}

You should be able to manipulate that to export to a file if necessary.

Blog: https://lowercasevblog.wordpress.com/
0 Kudos
scotty_p
Enthusiast
Enthusiast

That's awesome! Thanks for the quick response.

It's returning exactly what I need, but is there anyway to put that in a table format?

cluster1     16

cluster2     24

cluster3     8

something like that?

Thanks a lot!

0 Kudos
vbrad6841
Enthusiast
Enthusiast

Tab separated

$clusters = Get-Cluster | Get-View

foreach($cluster in $clusters){

$a = $cluster.name

$b = $cluster.summary.numhosts

"$a `t $b" | FT

}

Comma separated

$clusters = Get-Cluster | Get-View

foreach($cluster in $clusters){

$a = $cluster.name

$b = $cluster.summary.numhosts

"$a, $b" | FT

}

Blog: https://lowercasevblog.wordpress.com/
0 Kudos
mattboren
Expert
Expert

Hello, scotty p and vbrad6841-

While vbrad6841 definitely gives a couple of ways that will return some data to the screen in tabular format, a PowerShell-y way to get this data would be to use the Select-Object cmdlet, and create a calculated property for the values that you desire.  Like:

Get-Cluster | Get-View -Property Name,Summary |
   
Select-Object Name, @{n="NumHosts"; e={$_.Summary.NumHosts}}

The added value here is that the data is returned as objects, which we know are part of what make PowerShell endlessly useful.  So, with these object, you could do things like Measure-Object to get sums, or Export-Csv the objects to put them into a CSV, or feed them to ConvertTo-Html to make a report, or <so on>.  Just wanted to add that tidbit about how to get from code that makes tables in a console window to code that makes objects with which to do <all the things>.

scotty_p
Enthusiast
Enthusiast

Thanks for your help.

0 Kudos
scotty_p
Enthusiast
Enthusiast

This is excellent. Exactly what I'm trying to do. Thanks!!!

0 Kudos