Hi Guys , I am total NOOB in CLI so please excuse stupid question.
I need your expert advice for very large environment , and will grant points .
I have a working script that alerts on our ESXi hosts disconnecting , maintenance mode , and NotResponidng
Its working well , but need to send one mail out , for all three of our VCenters
Current script only works for one VC at a time . How do I do ForEach and still pipe to the same CSV and HTML body
It would be nice to have a HTML and CSV output that looks something like this ( assuming there are current disconnects etc )
I have one set of credentials , that work on all 3 my VC's
VC1
Host1 Disconnected
Host2 NotResponding
VC2
Host3 Disconnected
Host4 NotResponding
VC3
No hosts disconnected/maintemance/notresponding for VC3
Here is my current code , with passwords etc hidden >
# Clear old sessions
Disconnect-VIServer VC01 -Confirm:$false
# Check VC VC01 for Disconnects and Maintenance mode and Not Responding
Connect-VIServer -Server VC01 -User FakeUSer -Password FakePassword
$Report = Get-VMhost -State Disconnected,Maintenance,NotResponding | Select name ,connectionstate
# parse info to be html ,and give it date stamp
$ReportHtml = $report | ConvertTo-Html | out-String
# Write out CSV file and give it a Data Stamp
$filePath = "C:\PS\Output"
$filename = "VC01disconnectedHosts"
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('MM-dd-yyyy_hh-mm-ss')
$Report | Export-Csv "C:\PS\Output\VC_$Currentdate.csv"
# Send info with Mail
Send-MailMessage -To Almero.rademeyer@bcx.co.za -Subject VMwareMorningcheckVC01$CurrentDate `
-SmtpServer mail.sanlam.co.za -From Almero.rademeyer@bcx.co.za `
-BodyAsHtml -Body $reportHtml -Attachments "C:\PS\Output\VC_$CurrentDate.csv"
Thank you in advance for help .