Highlighted
Expert
Expert

Host overall status

Jump to solution

Hi All,

I'm trying to generate the report for Host over all status from multiple vcenter server, but it while running the script. No error. Any pointers will be much appreciated.

$userbane = "domain\admin"

$encrypted = Get-Content D:\Scripts\scriptsencrypted_paswd_admin.txt | ConvertTo-SecureString

$Cred = New-Object System.Management.Automation.PsCredential($userbane, $encrypted)

$vCenters = (Get-Content "C:\Temp\VC1.txt")

$report = @()

foreach ($vcenter in $vcenters) {

    Connect-VIServer $vcenter -Credential $Cred

    foreach ($cluster in Get-Cluster -Server $vcenter){

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

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

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

Disconnect-VIServer -Server $vcenter -Confirm:$false

}

$report | Export-Csv -path c:\Temp\HostStatus.csv -NoTypeInformation -UseCulture

$sMail = @{

    From                       = 'mail@domain.com'

    To                         = 'mail@domain.com'

    Subject                    = 'Remote Site Host Report'

    Body                       = "Report. Sending now."

    Attachments                = 'C:\Temp\HostStatus.csv'

    Priority                   = 'High'

    DeliveryNotificationOption = 'OnSuccess', 'OnFailure'

    SmtpServer                 = 'smtp.ta.domain.com'

}

Send-MailMessage @sMail

Thanks

V

Tags (1)
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

You are not storing the result in the $report variable.

$report += Get-Datacenter |

Get-Cluster -PipelineVariable cluster |

Get-VMHost |

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

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


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

View solution in original post

5 Replies
Highlighted
User Moderator
User Moderator

I'm not sure what you did here, but it seems you copied only part of the solution I already gave in Solved: Generating report for mutiple vCenter |VMware Communities


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

0 Kudos
Highlighted
User Moderator
User Moderator

Look you can't just change the original question.

And in fact, now you are exactly back to where that thread I pointed to started.
You don't collect the results in $report inside the foreach loop.


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

0 Kudos
Highlighted
Expert
Expert

LucD,

My apologies. Thanks for pointing out. Now modified the above code, but it generate the report in power cli console only, however the CSV output is blank. i.e. 0 KB

pastedImage_0.png

Just want to confirm any error in code -- E = {$_.ExtensionData.OverallStatus}}}

Thanks

V

0 Kudos
Highlighted
User Moderator
User Moderator

You are not storing the result in the $report variable.

$report += Get-Datacenter |

Get-Cluster -PipelineVariable cluster |

Get-VMHost |

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

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


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

View solution in original post

Highlighted
Expert
Expert

Thank you. Sir LucD. You are awesome.

0 Kudos