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
You are not storing the result in the $report variable.
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
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
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
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
Just want to confirm any error in code -- E = {$_.ExtensionData.OverallStatus}}}
Thanks
V
You are not storing the result in the $report variable.
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
Thank you. Sir LucD. You are awesome.