VMware Cloud Community
chrisbather
Contributor
Contributor
Jump to solution

Host Status report

I would like to run a script to output a table. The table would have 3 columns, Cluster name, host name and Overallstatus. ( we only have 1 datacentre so don't need a column for that)

Cluster     Host     OverallStatus

Cluster1     Host1     Green

Cluster1     Host2     Red

Cluster2     Host3     Green

I can get the later 2 columns ok with the line;

Get-Datacenter "Datacentre name" | Get-VMHost | Get-View | Format-Table -Property Name, Overallstatus -AutoSize

Its getting the Cluster name added to the table as the first column that's the problem. Parent seems to be the cluster name property for vmhost, but its working it into the script.  Presumably this can be done in multiple ways and I am sure there is a simple way but i'm not finding it.

The plan is also to email this out, with the table being in the body of the email.

Any help would be gratefully received.

Chris

0 Kudos
1 Solution

Accepted Solutions
Jac_
Contributor
Contributor
Jump to solution

Get-Datacenter "Datacentre name" | Get-VMHost | Get-View | Format-Table -Property @{N="Cluster";E={Get-View -id $_.Parent | Select -ExpandProperty Name}}, Name, Overallstatus -AutoSize

View solution in original post

0 Kudos
5 Replies
Jac_
Contributor
Contributor
Jump to solution

Get-Datacenter "Datacentre name" | Get-VMHost | Get-View | Format-Table -Property @{N="Cluster";E={Get-View -id $_.Parent | Select -ExpandProperty Name}}, Name, Overallstatus -AutoSize

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is where the PipelineVariable parameter comes in handy.

Get-Datacenter | Get-Cluster -PipelineVariable cluster | Get-VMHost |

  select @{N = 'Cluster'; e = {$cluster.Name}}, Name,

@{N = 'OverallStatus'; E = {$_.ExtensionData.OverallStatus}} |

   Format-Table -AutoSize


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

0 Kudos
chrisbather
Contributor
Contributor
Jump to solution

Thanks this works

0 Kudos
chrisbather
Contributor
Contributor
Jump to solution

Thanks for the reply, this doesn't populate the OverallStatus column for me??

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are right, that property is not present on the .Net object.

But we can get it with a calculated property via ExtensionData.

I updated the code above.


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

0 Kudos