VMware Daily Health Check HTML Report PowerShell

I have been working on a daily check report for our VMware environment so that we don’t have to manually check each morning.

The report uses PowerCli to generate information and then output the results to a HTML file.

The report requires a few that either the old PowerCLI snapin is available or preferably the PowerCLi PowerShell module.

The script can either be run directly by a users with rights to query vCenter or by setting up a scheduled task.

The following prerequisite will be needed for the script to run.

  • PowerShell V4 or V 5
  • PowerCLI 6.0 or later version
  • vCenter 6.0 or later version

There will also need to be a mail server or relay server available for the report to be emailed.

This has been tested on PowerCLI version 6.0 and above. The version on the server I will be running from is 12.3.0 which is the latest release at this time.

The report checks

  • vCenter connection
  • VMware tools check
  • Snapshot older than the specified snapshots days
  • Host Alarms
  • VM Alarms
  • vCenter Alerts over the last 12 hours
  • Datastore under specified % free space

There are mandatory parameter that are required for the script to run and send the report.

  • VCServer = vCenter Server address
  • SMTPServer = Mail server address
  • Toaddress = destination email
  • Fromaddress = sending address
  • Report Export = folder report will be exported to

There are some variables at the start of the script that can be set to customize the report to only show the required snapshots days and datastore % free. In my case I wanted 3 days and below 20% free on datastores.

I have embedded the html CSS format in the script so it can be update to change the color, font size or font type.

Example of how to run the script is below



.\VMwareDailReportv1.ps1 -VCServer vcenter.domain.local  -SMTPServer mail.doamin.local -FromAddress VMwareReport@domain.local -toAddress Administrator@domain.local -ReportExport D:\Scripts\VMware\Daily_Report

Once completed the report should be emailed to the specified to address.

Below is an example of the report export.

The full script can be downloaded from.

Scripts/VMwareDailyReport.ps1 at master · TheSleepyAdmin/Scripts (github.com)

To create a scheduled task to run the report each morning go to scheduled task on the server or client that has PowerCLI installed.

Create a new task

Set the schedule.

Next we need to set PowerShell as the program to start and set the argument to similar to the below, updating the parameters and script location

-ExecutionPolicy Bypass -NoProfile -File D:\Scripts\VMware\Daily_Report\VMwareDailReportv1.ps1 -VCServer vcenter.domain.local -SMTPServer mail.doamin.local -FromAddress VMwareReport@domain.local -toAddress Administrator@domain.local -ReportExport D:\Scripts\VMware\Daily_Report

I don’t change anything on conditions tab and only update that stop task if running longer than an hour in the settings tab.

Once completed run the task to confirm all is working.

I will probable added to the script but this is just the initial version and thought it might be helpful to anyone who want to try automate some of there manual checks.

10 thoughts on “VMware Daily Health Check HTML Report PowerShell

  1. Hello, thx for your script.

    I have a problem with VMs Alarms part:

    In powershell constantly receiving following error:

    Checking for active VM alarms

    Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named ‘op_Addition’.
    At line:69 char:1
    + $VMAlarms += New-Object PSObject -Property $VMprops
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named ‘op_Addition’.
    At line:69 char:1
    + $VMAlarms += New-Object PSObject -Property $VMprops
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

    Like

    1. Hi Maxr91

      op_addition is usually an error caused by multi value property trying to be added to the array. I haven’t seen this when using the script before but will try recrate the issue in my lab.

      Like

    2. Hi Maxr91

      I found the issue it was due to the the alarms being combined when multiple VM’s had the same alarm state. I have modified the script and it should work now just tested in my lab. I have update the script on github if you want to give that a try.

      Liked by 1 person

      1. Hello,

        thx for your fast reply. I was thinking that will get a reply in months.
        I will test it for sure.

        One more thing which I noticed I am not able to correctly sort messages by time.
        It is sorted – but in a strange way
        03:15
        03:16
        03:17
        03:18
        03:19
        02:10
        02:11
        02:12
        02:13
        04:12
        04:13
        04:15
        04:16

        I hope I am not asking too much.
        I am really grateful for what you are doing.

        Thx for your help.

        Like

    1. Hi Maxr91

      The vCenter alerts can be sorted using sort-object.

      on line 241 change

      $ActiveVCAlert = $VCAlerts | Select-Object @{N=”vCenter Events”;E={$_.FullFormattedMessage}},CreatedTime |

      to

      $ActiveVCAlert = $VCAlerts | Select-Object @{N=”vCenter Events”;E={$_.FullFormattedMessage}},CreatedTime | Sort-Object -Property CreatedTime -Descending |

      That should then sort the results from newest to oldest.

      I updated the script on github now.

      Like

  2. Everything is working fine for me except one thing. If run this script on a different machine, how do I specify the credentials for my mail server? If run from my mail server, no issues report generated and mail report. But I would like run on a different machine but with different smtp server, where or how do we add the smtp mail credential, thanks!

    Like

    1. Hi mykrbc

      The command Send-MailMessage on line 273 and 274 would need to be modified to put in the credentials but I haven’t ever need to do this before. What I usually do is add the server or client’s IP that I generate reports to the allowed relay list on the mail server.

      Like

    1. Hi Sakkie

      For the VM power status that would need to be added to the select-object on line 176. I am not checking host status in the report just alerts but it could be added would need to rewrite it a bit. Will try to have a look at it over the next few weeks.

      Like

Leave a comment