PowerCLI: Daily Report
This script will save you time and resources.
I have been using this script for the past month and it has highlighted a number of issues which would have been harder to find without it.
Daily Report does what it says on the tin, it runs as a scheduled task before you get into the office to present you with key information about your infrastructure in a nice easily readable format.
This script picks on the key areas of the virtual infrastructure and reports it all in one place so all you do in the morning is check your email.
One of they key things about this report is if there is no issue in a particular place you will not receive that section in the email, for example if there are no datastores with less than 5% free space (configurable) then the disk space section will not show in the email, this ensures that you have only the information you need in front of you when you get into the office.
So what areas does this script report on ?
Firstly it will give you a very brief summary detailing some of the critical information, it does not list every name and how many cpu’s or how much memory your vms and hosts have as that would be a audit report not a daily report.
There is a configurable section at the start of the script where you can set how many days old you would like your snapshots to be allowed in your infrastructure, anything over this will show in the report, it will even resolve the name ( the machine running the script must be part of an Active Directory Domain) so that you can forward this email on to them and ask them if they still need the snapshot.
There is a section which lists all datastores that have less than x% free space.
The below section notes any virtual machines which have been created in the last x days and who created these.
Similarly any VMs which have been deleted.
Any Virtual Center Events which have been logged during the given timeframe.
Any VM’s which have no VMtools installed.
The script will also hook into your virtual center server and tell you what the state of all VMware services are, if you use a different account to access you virtual center than the one which is running the script then you can set this at the start and the first time the script runs after this it will ask you for the credentials of the account and store these in an encrypted file for future use.
Also in the report but not screen captured is:
- Any Windows events from the Virtual center server which are related to VMware
- Any VMs which have CD-Rom or Floppy Drive’s connected
- Any hosts in Maintenance Mode
- Any Hosts ina disconnected state
At the bottom of he script is also an area which you can uncomment to save a the daily report as a htm file in a specific folder.
I think that’s it !
If there is anything missing please let me know and I will add it to future versions.
To run this script simple setup a scheduled task as per my previous post running the script and passing it your VI server as a parameter as below:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ ” & “C:\Scripts\DailyReport.ps1 TESTVC01″







about 7 months ago
Alan – Thanks for the great script! It works flawlessly as always!
about 7 months ago
Love the script, modified the ‘No Vm Tools’ section as Killsystem posted to include VMs with outdated tools also.
A question though, my output does not appear as you screenshots above show. Rather than red and blue headers with white lettering, I only get white backgrounds with black letters. Is there a switch to turn on/off the formatting that I have missed?
Thanks
Mark
about 7 months ago
Very nice.
Not being a windows person and not up to snuff on Powershell, what would you suggest to cleanly update this script to ignore certificate errors when connecting to the virtual center instance? It does connect, but this script will fail if certificates are not set up. Was able to hard code removing lines 396 thru 400 and all went well. Not elegant, but got the job done. Thanks.
about 7 months ago
Hi lovely script it works well for me . The only problem is the services section is empty ..Looks like a Aceess denied error
about 7 months ago
Hi again, i add “@{N=”Host”;E={$_.host.name}}” in VC errors loop to get hostname for any error (if not VC)
Hope it help for future version
about 7 months ago
Alan,
You never cease to amaze me with these scripts. It feels like Christmas everytime i come pay a visit !
about 7 months ago
Cheers Alan, this is a great script. I can leave VC to do it’s own thing now and see what’s going on with this report. What a life saver.
about 7 months ago
@NiTRo
Thanks again
about 7 months ago
@Mark
The output should be defined by your html renderer for your email client, have you tried saving the content as a html file which can be enabled at the bottom of the script or try a different email client.
about 7 months ago
@DJLO
Thanks, that’s an amazing comment, im pleased people are getting as much as I do out of this.
about 7 months ago
@cxo
Strange, I have no certificate setup on my VI and it works fine ?!
about 7 months ago
@edward
You will need to configure the account which has permissions for your vc its one of the options near the top of the script. Let me know if you need me to video it as its not as easy as id like.
about 7 months ago
@Rob P
Nice one Rob, im pleased its working for you, hope you and everyone else are ok.
about 6 months ago
@Virtu-Al After some playing I finally got the disk usage for VM’s it works really well. Thanks again for the great script to work from.
about 6 months ago
I just scheduled the script on a Windows Server 2008 x64 machine and want to share the commando: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ ” & “c:\scripts\ps\VMware_Daily_Report.ps1 vCenter”
about 6 months ago
Alan,
great script. Unfortunately i need to relay mail through a secure exhange environment and need to authenticate to the server to said mail. Is there an easy way to do this?
about 6 months ago
@Graham
You could try something like this… replace your mail function in the script with:
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$mailer.Credentials = New-Object System.Net.NetworkCredential(“username”, “passwd”);
$msg.IsBodyHTML = $true
$mailer.send($msg)
}
about 6 months ago
Alan, really like this script and would like to adopt as part of our internal health checks, however at the end I am getting the table with services and then just after the table it repeats the last two entries again, see below:
VMware Update Manager ServiceRunningAutoOK VMware VirtualCenter ServerRunningAutoOK
/html>
It also ends there without any vmkernel messages section, am I missing something?
Thanks again,
Dan
about 6 months ago
@Dan Yates
Hmmm, havent seen that one before, would you be able to email me a copy of your results please ? My contact information is in the contact me tab at the top of this page.
about 5 months ago
Hi all
Will this script run with esx 3.5
thanks in advance
Robin
about 5 months ago
@robin farnworth
Yes, it was written for 3.5, let me know if you have issues
about 5 months ago
Sir, truly awesome. Hats off to you!
about 5 months ago
@Virtu-Al
Yes, I have enabled the HTML output which does appear as your sample when viewed in IE. But it doesn’t appear to use the text formatting when we view it as e-mailed in MS Outlook.
about 4 months ago
Hello
i don’t resolve the Scheduled TASK!!
Have you got a Guide (or requisites) sto solve this line?
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ ” & “c:\scripts\ps\VMware_Daily_Report.ps1 vCenter”
I’ve find error of Set-ExecutionPolicy and i set the line in this mode:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe Set-ExecutionPolicy Unrestricted…
but don’t work.
The “VMware_Daily_Report.ps1″ is this file PowerCli?
What’s the word at the and of the line “vCenter” ?
Why there’s a double > ″ ” in the middle?
about 4 months ago
@Andrea
The vCenter bit at the end is the hostname of your virtual center, it passes the information as a parameter to the script, What I normally do is run my cmd from a dos prompt until it works and then copy and paste the line into the run window of the scheduled task.
about 4 months ago
hello, i’m trying to run v2 of the script and there is a part that references “mycred.crd” file. I’ve placed uid/pw but it doesn’t take it. How is this file supposed to be created?
Thanks,
-N
about 4 months ago
@nsocrates
This part is used to communicate to your vCenter server over WMI, if your current account has access to that servers then you will be fine and do not have to set this, if not then this file is auto-created by the script, all you need to do is put a username in the $SetUsername = “” bit, so if I set it to $SetUsername = “mydomain\me” then next time you run the script it will ask you for a username and password, enter the same username (mydomain\me) and the password.
The credentils will then be stored in that file encrypted so that every other time you run the script it will have the correct permissions.
A little complicated I know but it was the easiest way I could find of doing it.
about 4 months ago
Thank you, it worked for both v2 and v3. The information reported is very helpful. I used it today and taking some actions on what was reported already i.e. snapshots, vmotion violations.
Excellent!
-N
about 4 months ago
@nsocrates
Great, glad you got this working
about 1 month ago
The Script runs well, except at some points at the following exception.
15:38 ..Checking Snapshots
Exception calling “ReadNextTasks” with “1″ argument(s): “A general system error
occurred: Object not found”
At C:\tools\VMware_Daily_Report3.ps1:420 char:45
+ $collection = $collectionImpl.ReadNextTasks( <<<< $tasknumber)
Exception calling "ReadNextTasks" with "1" argument(s): "A general system error
occurred: Object not found"
about 1 month ago
Hi,
Great script and is very useful. Couple of my ESX servers doesnt have LUN’s presented, has only local HD. So the script fails at get-scsilun cmdlet. Is there some kind of error handling we could introduce?
Please help
about 1 month ago
@Rajeev
You can turn that part of the script off if you dont need it, check near the top, it will probably speed it up for you too.
about 1 month ago
Thanks. I need that part of script and i’ve introduced a small trap to continue on errors.
- One more Query regarding the number of slots in the clusters. In my environment there are 4 clusters with differnet number of slots.
- What value should i put for $numslots.
Appreciate your help.
about 1 month ago
@Rajeev
Thats an interesting question, in order for you to work that one out, I suggest you read this post first, also the link in the post to Duncans site is well worth a read….
http://www.virtu-al.net/2009/10/06/ha-slot-size-information/
about 3 weeks ago
Hi I must thank you for the excellent script you make.
I have only have one problem.
I don’t know what happens but every time I run this script I get the information twice in my report.
for example I have 7 hosts and my report gives 14 etc.
Can you maby explain what is going wrong.
regards,
Marc
about 3 weeks ago
@Marc
I have never seen that before, it sounds like you are making two connections, im not even sure that can be done !
Have you modified any part of my script at all ?
What happens if you connect to your host manually through PowerCLI and do a get-vmhost, do you get duplicate Hosts then ?
about 3 weeks ago
have solved the problem. It was a mistake that I make. Sorry for the inconvenience.
regards,
Marc
about 3 weeks ago
@Marc
Glad you got it sorted !
about 2 weeks ago
I cannot get the script to run and connect to my vCenter Server. Keeps saying specify a VI server name. I have tried to do this and also edit the script to include this but still not running…can anyone help ?
about 2 weeks ago
@Amit
You shouldnt need to ammend the code, just add the name of your vCenter server after the name of the script, it will then use this as a parameter, ie:
C:\Scripts\DailyReport.ps1 TESTVC01
about 1 week ago
thanks for the script, how do we point this script to talk to only one datacenter…
we have multiple datacenters listed in our environment and it will be good if this can point to only one datacenter..
about 1 week ago
Suresh,
No not as yet but you should be able to with some manipulation of the code.
about 2 days ago
Very powerful script, but i miss the output of VMs which has no VMware-Tools installed
about 2 days ago
Are you using V3 of this ? I think i fixed it there.
about 1 day ago
Thank you, V3 works! The link on bottom of this page points still to V2.
about 1 day ago
Thanks, Updated now !