VMware

VMware Healthcheck script

VERSION 7 Published

Created on: Aug 28, 2008 1:05 PM by ibeerens - Last Modified:  May 22, 2009 11:11 AM by ibeerens

VMware Healtcheck script

Introduction:

Healthcheck is a Powershell script that reports information like snapshots, VMware tools version, datastore space, CDROM and/or floppy drives connected, VM details etc. to HTML and e-mail the output. This script can be scheduled so that for example you get every week a rapport in your mailbox with the status of the VMware environment.

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 <mailto:powershell@ivobeerens.nl>"
Specify the from field

$mailto = 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 http://communities.vmware.com/images/emoticons/happy.gif
Attachments:
Average User Rating
(2 ratings)




Comments

Mar 23, 2009 8:54 AM sfortuna74  says:

Hi -

We have recently started using this script and found it to be more helpful than we could have imagined. We are having one problem, however, which I hope you can help us with. We can only get the script to run when we are logged into the server. When the script is set to run as a scheduled task, we get the email report, however all the fields are empty. I then mofified our batch file to write to an error log, via "2>&1 > error.log" and the output I see when the script attempts to run as a scheduled task is as follows -
You are not currently connected to any servers. Please connect first using Connect-V
IServer
Might you be able to help us understand what we need to do to make this error go away?

Thank you very much for sharing the script and for your time -

Steve Fortuna

May 11, 2009 5:16 AM dmn0211  says: in response to: sfortuna74

Try the fix located here.
scheduled tasks + credentials not passed to script

http://communities.vmware.com/message/1162102#1162102

Oct 7, 2009 9:50 PM VRudi777  says: in response to: dmn0211

hi,

firstly, thank you very VERY much to all involved with the script, I is a great utililty and has made my life much easier, so cudos to the smart people :)

I would like some help however. I have downloaded the modified script and I am trying to start it with a batch file. It does not run as a scheduled task, after reading this thread I understand that I shoudl create a profile for the user account which I use to run the script. there is no profile.ps1 file to edit on this account. can someone please help me step by step how to get the profile.ps1 file created and edited so that I can schedule this task to run it?

thanks again to the community!

Oct 8, 2009 4:33 PM dmn0211  says: in response to: VRudi777

Did you try adding the section below to your PS script?

$USER = $env:username
$APPPATH = "C:\Documents and Settings\" + $USER + "\Application Data"

#SET THE APPDATA ENVIRONMENT WHEN NEEDED
if ($env:appdata -eq $null -or $env:appdata -eq 0)
{
$env:appdata = $APPPATH
}

The 1.5 toolkit update required this fix.

As for the batch file, you don't really need one to run a powershell script as a schedule task.
http://www.virtu-al.net/2009/07/10/running-a-powercli-scheduled-task/

If you want to edit the profile.ps1, the simplest way is to use powergui.
http://www.powergui.org/index.jspa

In addition, you can also look at the script located here for some additional ideas on reporting. And scripting

http://www.virtu-al.net/2009/08/18/powercli-daily-report-v2/

Oct 8, 2009 9:42 PM VRudi777  says: in response to: dmn0211

thanks I got it working... had to create a new profile in powershell and then pasted in the one liner from the previous page...

thank you for the extra links! :)

 

More by ibeerens

Developer Social Media

Communities