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
Get-Datacenter "Datacentre name" | Get-VMHost | Get-View | Format-Table -Property @{N="Cluster";E={Get-View -id $_.Parent | Select -ExpandProperty Name}}, Name, Overallstatus -AutoSize
Get-Datacenter "Datacentre name" | Get-VMHost | Get-View | Format-Table -Property @{N="Cluster";E={Get-View -id $_.Parent | Select -ExpandProperty Name}}, Name, Overallstatus -AutoSize
That is where the PipelineVariable parameter comes in handy.
select @{N = 'Cluster'; e = {$cluster.Name}}, Name,
@{N = 'OverallStatus'; E = {$_.ExtensionData.OverallStatus}} |
Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks this works
Thanks for the reply, this doesn't populate the OverallStatus column for me??
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