Check Which VM is PoweredOff

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.

Connect-VIServer <VCenter Domain Name>

$smtpsettings = @{

To =  “User@domain.co.za”

From = “support@domain.co.za”

Subject = “VMware PoweredOff Systems”

SmtpServer = “<smtp server details>”

}

$objs = @()

$emailBody = “<table border=’1’><tr><th>Name</th><th>PowerState</th><th>”

$csvs = Get-VM | Where-Object {$_.Powerstate -eq “PoweredOff”} |  select Name,PowerState

foreach ( $csv in $csvs )

{

      $emailBody = $emailBody + “<tr><td>” + $csv.Name + “</td><td>”  + $csv.PowerState + “</td></tr>”

}

$emailBody = $emailBody + “</table>”

Send-MailMessage @smtpsettings -Body $emailBody -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8)

Add the above on to a text document. Then save it as a .ps1 file. When you run it, it will run in Powershell and email you.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.