postheadericon VMware Powershell Healthcheck script

Healthcheck is a Powershell script that reports information like snapshots, VMware tools version, datastore space, CDROM and/or floppy drives connected etc. to HTML and e-mail the output to a person or distribution list.

Reason for creating this script:

As VMware Consultant I see a lot of common problems in VMware environments like:

- Snapshots are enabled and forgot the commit to the VM.

- Datastores are almost full (for example if snapshots are enabled)

- VMware tools versions are different

- CDROM and floppy drives are still mounted to the VM

- Virtual Machines have CPU and Memory limits or reservations (VMs are swapping)

- In the VM, the VMware Tools timesync option is not enabled

In the Virtual Infrastructure Client (VIC) it is difficult to see this sort of information. By creating a Powershell script,  I can do a quick inventory.  In a lot of VMware environments I created a scheduled tasks, so the script runs once a week and sent to HTML rapport to the administrator.

What does the script:

I wrote a Powershell script with HELP from the VMTN community that makes a HTML file and sent the output by e-mail to a person or distribution list.  The Healthcheck script does the following checks:

- VMware ESX hardware

- VMware ESX versions

- VMware VirtualCenter versions

- Active snapshots

- CDROM and Floppy drive(s) mounted to the VM

- Datastore information like capacity, free space and the percentage free space

- VirtualMachine (VM) information like VMware tools version, CPU, Memory reservations and limits etc.

- On what VMs VMware Tools timesync is not enabled

Requirements:

The following software must be installed:

Microsoft Powershell 1.0 (http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx)

VMware Infrastucture (VI) toolkit for Windows 1.0

http://www.vmware.com/download/sdk/

Set the ExecutionPolicy in Windows Powershell to RemoteSigned by using the following command:

set-ExecutionPolicy RemoteSigned

Installation:

- Unzip the Healthcheck.zip script to a directory on the VC server for example.

- When the ZIP if unpacked there are two files:

- Healthcheck.ps1, this is the Powershell script

- Style.CSS, controls the HTML layout

Configuration:

- Edit the Powershell.ps1 file

edit the following variables:

$vcserver=”localhost”

Enter the VC server, if you execute the script on the VC server you can use the localhost name

$filelocation=”D:\temp\Healthcheck.htm”
Specify the location where to store the HTML output

$enablemail=”yes”
Enable (yes) or disable (no) to sent the script by e-mail

$smtpServer = “mail.ivobeerens.nl”
Specify the SMTP server in your network

$mailfrom = “VMware Healtcheck <powershell@ivobeerens.nl>”
Specify the from field

$mailto = ivo@ivobeerens.nl

Specify the address where the e-mail to sent  to

Usage:

Manually run the Healthcheck.ps1 script”:

1. Open Powershell

2. Browse to the directory where the Healthcheck.ps1 script resides

3. enter the command:

./Healthcheck.ps1

To create a schedule task in for example Windows 2003 use the following syntax in the run property:
Powershell -command “& ‘path\Healthcheck.ps1′
edit the path

Powershell -command “& ‘path\Healthcheck.ps1′

edit the path .

Future:

- List Orphaned VMDK’s

- Add performance information like VM usage

- Check timesync on the VMware hosts

Happy testing :-)

Download Link: Healthcheck script

The script is posted on the VMware Powershell contest forum, link

Some screenshots of the HTML output:

 

1JPG

2

3

 

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live

27 Responses to “VMware Powershell Healthcheck script”

  • Nice script, would be handy for updating an intranet

  • Ross Brown:

    A nice script, thanks for sharing :)

  • Scarecrow:

    Very nice script. Love the detail.

  • Curtis L. Smith:

    Very nice work. I have found this script to be very usefull. I have a couple of suggestions.

    1) Change the CSS to be part of the HTM file so that is it not dependent on the style.css file. This will make it so that the report maintains the style even when e-mailed.

    ConvertTo-Html –title “VMware Health Check ” –body “Date and time”,$date -head “body { background-color:#EEEEEE; } body,table,td,th { font-family:Tahoma; color:Black; Font-Size:10pt } th { font-weight:bold; background-color:#CCCCCC; } td { background-color:white; } ” | Out-File -Append $filelocation

    2) I added the following so that I could have the report send to a network share (IE. Sharepoint)

    $enablnetshare=”yes”
    $netshare=”\\server1\share2\subdir1\subdir2\etc.”

    ####################################
    # Copy to Sharepoint Netowrk Share #
    ####################################
    if ($enablnetshare -match “yes”)
    {
    copy $filelocation $netshare
    }

  • Curtis L. Smith:

    Well, looks like the blogging engine stripped out the style tags on suggetion 1, but you get the point.

    Thanks again

  • [...] That night I pondered how I could keep an eye on snapshots so they don’t bite me again – and a few searches led me to this very handy script - http://www.ivobeerens.nl/?p=106 [...]

  • admin:

    Thanks for the suggestions Curtis!

  • Mark Hawkins:

    @Curtis L. Smith
    Curtis,
    Would you mind sharing your version of this script with the CSS stuff built in? I am very interested in that.

    Thanks!

    -Mark

  • Peter:

    After a bit of trial and error. Find the two ConvertTo-Html lines and replace them with this!

    ConvertTo-Html –title “VMware Health Check ” –body “VMware Health script” -head ” body { background-color:#EEEEEE; } body,table,td,th { font-family:Tahoma; color:Black; Font-Size:10pt } th { font-weight:bold; background-color:#CCCCCC; } td { background-color:white; } ” | Out-File $filelocation

    ConvertTo-Html –title “VMware Health Check ” –body “Date and time”,$date -head ” body { background-color:#EEEEEE; } body,table,td,th { font-family:Tahoma; color:Black; Font-Size:10pt } th { font-weight:bold; background-color:#CCCCCC; } td { background-color:white; } ” | Out-File -Append $filelocation

  • Peter:

    actually leave your email and I’ll send it to you! same problem as Curtis when posting

  • Bill Scott:

    Please send the script to: Bill.Scott@SetClear.com
    Thank You!

  • Firoz Basha:

    Very Nice script.. Thanks..

    Peter can you share the ConvertTo-Html lines. This is my email Id “firoz_basha@aol.in”

    Thanks in advance

  • Jason:

    Hey Curtis- could you send it to me as well? Thank you. jason[dot]george[at]valero[dot]com

  • Drew:

    Send to me as well please! ddennis at beazer dot com

  • Scott Banrett:

    Please send to me to sbarnett[at]adesa[dot]com

    thanks

  • David:

    Very very nice, great work! I suggest the following enhancement to see the size of each windows disk in a VM, space used, space free and percent free (not just percfree). I however did not sort by percent free as it’s sorted by VM, up to you! I used some new variables which are also listed.

    ##################################################
    # Percentage freespace on partitions in the VM #
    ##################################################

    $hdCapacity = @{ N = “Capacity (GB)”; E = { % { $_.Capacity / 1000000000 } } }
    $hdFreeSpace = @{ N = “FreeSpace (GB)”; E = { % { $_.FreeSpace / 1000000000 } } }
    $hdSpaceUsed = @{ N=”Used (GB)”; E={ ( $_.Capacity – $_.FreeSpace ) / 1000000000 } }
    $hdPercFree = @{ N=”PercFree”; E={ [math]::Round( ( 100 * ( $_.FreeSpace / $_.Capacity ) ),0 ) } }

    Get-VM | Where { $_.PowerState -eq “PoweredOn”} | Get-VMGuest | Select VmName -ExpandProperty Disks | Select VmName, Path, $hdCapacity, $hdSpaceUsed, $hdFreeSpace, $hdPercFree | ConvertTo-Html –title ” Percentage freespace partitions inside the VM” –body ” Percentage freespace on partitions inside the VM.” -head “” | Out-File -Append $filelocation

  • MuscleRush:

    Please send to me too maher74[at]Hotmail[dot]com
    i tried not using the CSS file but just dont want to work

    thanks..

  • more simple to embedd the css

    ##include the css
    $CssFileName=”.\style.css”
    $css = Get-Content $CssFileName
    $style =”"+$css+”"
    ## include it in the first call to the convertTo-Html
    ConvertTo-Html –title “VMware… ” –body “VMware…” -head $style | Out-File $filelocation
    ## and remove all other -head

    And the final result is a html mail with a nice look
    This is working perfect in my variant of the script
    -ph Koenig-

  • Biswa:

    Please share the script once you incorporate the items mentioned in “Future”.

  • Damian:

    This is a really nice script, please forward ConvertTo-Html details to dcarter[at]family[dot]co[dot]uk

    Thanks

    D

  • Rob:

    @ph Koenig

    Could you please send me the “embedded css” script?

    rvandijck[at]gmail.com

    Cheers!
    Rob

  • Rob:

    @admin

    Ivo,

    I’ve scheduled this script as a scheduled task with a service account with administrator rol in VC (Datacenter level). Worked perfect untill we upgraded to VC2.5U4.

    What could be the reason??

    Also the VI Toolkit got updated, maybe this is the reason?

    Current VI Toolkit version:

    VI Toolkit Version
    ——————
    VMware VI Toolkit for Windows 1.5 build 142961

    Any help muchely appreciated!

  • Kevin:

    Can you pleasae send me the update script with the ambedded CSS code as well?

    my email is pc21geek[AT]yahoo[DOT]com

  • Pramod:

    This is a amazing script . It helped my 2 weeks work .. !!

    Is there a script which would help me to disconnect CRDOM’s on bunch of VM’s at a shot

  • Thgrey:

    Thanks for your script

    Is it possible to add color in the html file for percfree. for example red color if percfree less than 10%

  • Jose:

    Can you send me the updated script?

Leave a Reply