
Here is a script on VMware via Powershell. As long as you have installed the PowerCLI module, you can run this via the standard Powershell. I have taken the script and created a PS1 file to run through the list and email it to you. This will help in the cases whereby you have multiple hosts and needs to be aware of the connection status. Now all your resources may not have access to VCenter or may not know how to check. This email will help to notify the team.
Connect-VIServer <VCenter Server> -user <Username> -Password <Password>
$smtpsettings = @{
To = “user@domain.co.za”
From = “support@domain.co.za”
Subject = “VMware Hosts Connection Status”
SmtpServer = “<smtp server”
}
$objs = @()
$emailBody = “<table border=’1′><tr><th>Name</th><th>ConnectionState</th><th>PowerState</th><th>”
$csvs = Get-VMHost | Sort-Object Name
foreach ( $csv in $csvs )
{
$emailBody = $emailBody + “<tr><td>” + $csv.Name + “</td><td>” + $csv.ConnectionState + “</td><td>” + $csv.PowerState + “</td></tr>”
}
$emailBody = $emailBody + “</table>”
Send-MailMessage @smtpsettings -Body $emailBody -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8)
The above is simple script to get-VMHosts and displays the power and connection status. This is a good start if you do not have vROPS installed.
Here is how the email would look like

Leave a Reply