PowerCLI

 View Only
  • 1.  Find Cluster name in get-view

    Posted Oct 12, 2015 05:32 PM

    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



  • 2.  RE: Find Cluster name in get-view
    Best Answer

    Posted Oct 12, 2015 06:26 PM

    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.



  • 3.  RE: Find Cluster name in get-view

    Posted Oct 12, 2015 06:55 PM

    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!



  • 4.  RE: Find Cluster name in get-view

    Posted Oct 12, 2015 07:12 PM

    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

    }



  • 5.  RE: Find Cluster name in get-view

    Posted Oct 13, 2015 01:39 AM

    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>.



  • 6.  RE: Find Cluster name in get-view

    Posted Oct 13, 2015 12:36 PM

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



  • 7.  RE: Find Cluster name in get-view

    Posted Oct 13, 2015 12:35 PM

    Thanks for your help.