PowerCLI: Daily Report V2
Firstly I would like to thank everyone who took the time to comment on my previous Daily Report script, I really appreciate the feedback and have never had so many comments !
Now onto V2…
This one will take a while longer to run than the last script but as its a scheduled task we are not really worried about that, we are hardly going to sit there and watch it running !
I think you will agree the results are worth the wait:
What’s new
- Bug Fixes
- Active VMs count
- Inactive VMs count
- DRS Migrations count and list
- Correct NTP Server check for each host
- VMs stored on local datastores
- NTP Service check for each host
- vmkernel warning messages for each host
- VM CPU ready over x%
Bug Fixes
I have fixed the bugs which were mentioned in my previous posts comments, thanks to all for helping me find these. I have also added a few other tweaks along the way to improve output etc.
Active VMs count
In the General Details section there will now be a count of the number of VMs which are powered on.
Inactive VMs count
In the General Details section there will now be a count of the number of VMs which are powered off.
DRS Migrations count and list
In the General Details section there will now be a count of the number of DRS migrations over the given timescale (configurable in the config section), these migrations will also be listed in the DRS Migrations section later in the report:
Correct NTP Server and service check for each host
In the config section of the script you must specify your correct ntp server name, the script will then check to make sure all your hosts are using this NTP server and that the NTP service is running, if they are not it will report on these as below:
VMs stored on local datastores
The script will check to see if you have any VMs which reside on local storage if they do it will report these. At the top of the script you can add exclusions for things like templates or machines you know are allowed to be on local storage.
vmkernel warning messages for each host
Each host’s vmkernel log file will be checked and if any warning messages are being displayed these will be included in the report:
VM CPU ready over x%
Any VMs with a CPU %RDY over the configurable amount will be displayed in the report as below:
I hope you enjoy these additions and find them as useful as I do.
Please leave your comments below !







about 6 months ago
Great work again, Alan! Keep it up!
about 6 months ago
@Sven Huisman
Thanks Sven
about 6 months ago
Alan, you’ve done it again. It does everything except stir my coffee. Well done mate.
about 6 months ago
Alan,
Wonderful work. My boss thinks i’m some kind of genius busting out all these reports !
Seriously, your scripts have made my day to day job a whole lot more enjoyable
about 6 months ago
@Rob P
thanks mate
Im working on the coffee one at the moment but can only get tea
about 6 months ago
@DJLO
Thanks for the great comments, I will look forward to the comission when you get the pay rise
about 6 months ago
Would it be possible to include Update Manager information in the next version? Number of compliant and non-compliant updates on a host/VM level would be useful.
about 6 months ago
@Grasshopper
I will see what I can do.
Now we are getting to the hard stuff, I like it
about 6 months ago
Alan, you really add great stuff in the V2 ! thanks again !
about 6 months ago
@NiTRo
Thanks man, and thanks for your previous comments and bug finding !
about 6 months ago
Alan, Thanks for this wonderful work. I am new comer to vmware world and my first thing is to implement your script!. Now everyone thinks i am a genius! (due to your work). Thanks again. I worked on unix shell/perl a lot and always ignored powershell, but your script ignited me on powershell
.
I did bit of modification on your first script and adding the same to V2 now. Additions were minor and mainly the following:
1) Passing email ID along with VIServer but both optional with default hardcoded
2) It will add vmware snapin if not already loaded
3) I also went crazy and included total runTime as it takes about 5 minutes in our environment (on the V1 script).
Option 2 made easy for me to run via windows task schedular. If you think any value addition, i can send the code.
Once again thank you.
about 6 months ago
I’m getting the following error:
Get-VM : The argument cannot be null or empty.
At C:\utils\DailyReportV2.ps1:588 char:36
+ $LocalVMs = @($LocalOnly | Get-VM <<<< | Where { $_.Name -notmatch $
LVMDoNotInclude } |Get-View | Select Name, @{N="VMX";E={$_.Summary.Config.VmPat
hName}})
What does that mean?
about 6 months ago
@Mark
Sure, dop me a mail with the code, always intereasted in improvements !
Thanks for your comments
about 6 months ago
@Brandon Yap
I will look into that one, do you have any vms on local storage ?
about 6 months ago
Simply great!
Again I had to comment out the “did we really connect to vCenter” check as it was assuming false over here even when it connected.
Also, line #596… When run interactively I see an error: “Select-Object : The term ‘Get-VMHostNtpServer’ is not recognized as a cmdlet”… Process continues to work however. Am I just missing a function or is this a bug. How hard wold it be to sort the ESX Hosts in the “NTP Issues” report?
Also, on the “VMs Removed” section… I have it set for default (i.e. 5 days), but it only shows the last 1 day worth of entries. Anyone else see this?
Again, overall, simply very useful.
about 6 months ago
@Virtu-Al
FYI… I see this issue as well. No local storage VMs here (at least not at the moment)
about 6 months ago
@cxo
Do you have the latest version of powercli installed ? Sounds like your missing a cmdlet there with get-vmhostntpserver. I will sort the names, well spotted.
The VMs Removed and Added both use the same number so should be ok, certainly works for me.
I will put a fix for the error on the local stored vms bit.
Thanks for your comments !
about 6 months ago
@Virtu-Al
no, I am running a slightly older version. If that is the issue here, I will investigate upgrading as appropriate. Thanks for the feedback.
about 6 months ago
@cxo
The best thing to do is type get-vicommand from the powercli prompt and see if it has get-vmhostntpserver in the list.
about 6 months ago
Thanks for the tip. I indeed do not have that in the list. I am a rather good bash shell guy, just ignorant with Windows, hence the many questions.
about 6 months ago
@cxo
Dont apologise, I couldnt tell you a thing about bash !
Im just glad I am slowly converting you to PowerCLI and PowerShell !
about 6 months ago
@Virtu-Al
downloaded newest things and all is happy again! NTP checking works and “removed” VMs history goes back more than 1 day.
Still have the issue when logging on and we do not have SSL certificates set up so I have to assume connections work (same with PowerGUI, for example), but all works anyway.
about 6 months ago
Great script, Al! Thanks so much for contributing it to the community.
I’m having trouble with the NTP server check. All of our ESX hosts are configured with multiple NTP servers:
0.us.pool.ntp.org
1.us.pool.ntp.org
2.us.pool.ntp.org
3.us.pool.ntp.org
How do I check for that with your script?
Also, I hacked it up a bit to provide CPU and Memory Usage over the last week. If you’re interested, I’ll email you the code I used. And if you have any tips on how to do it better, I’m open to advice!
about 6 months ago
@Virtu-Al
I could not locate your email/contact details, so posting the difference here:
### At the beginning
param([string] $EmailTo, [string] $VISRV)
$scriptVersion=”2.1 [18-August-2009]”
$vcServer=viserver.mydomain.com
if ($VISRV -eq “”){
$VISRV=$vcServer ### To use default if not given in argument
}
$to_email=myself@mydomain.com
if ($EmailTo -eq “”){
$EmailTo=$to_email ### To use default if not given in argument
}
$stDate=Get-Date ## To store script beginning time
### Following is to add the snap-in if not already loaded
##################
# Add VI-toolkit #
##################
if ( !(Get-PSSnapin VMWare.VimAutomation.Core -ErrorAction silentlyContinue )) {
Add-PSsnapin VMware.VimAutomation.Core
}
### Since it now runs over 10 minutes on V2, some nice screen to display
clear
write-host “VMWare Daily Report – $scriptVersion” -foregroundcolor DarkBlue -backgroundColor DarkCyan
write-host “Started on : ” -nonewline -backgroundColor DarkCyan; write-host $stDate -foregroundcolor white -backgroundColor DarkCyan
write-host “VI-Server : ” -nonewline -backgroundColor DarkCyan; write-host $VISRV -foregroundcolor white -backgroundColor DarkCyan
write-host “Email to : ” -nonewline -backgroundColor DarkCyan; write-host $EmailTo -foregroundcolor white -backgroundColor DarkCyan
….
….
### Following code is for servers that dont use C:\ for profiles
$USER = $env:username
$APPPATH = $env:userprofile + “\” + $USER + “\Application Data”
#SET THE APPDATA ENVIRONMENT WHEN NEEDED
if ($env:appdata -eq $null -or $env:appdata -eq 0)
{
$env:appdata = $APPPATH
}
$VIServer = Connect-VIServer $VISRV
….
….
### I would like to know the running user/script version on the report
Report created on $(Get-Date)[Script Version : $scriptVersion Run by user : $ENV:user ]
….
….
### Following bit included to know how many windows and how many Linux we got
$windowsVM= ” ” + (@($FullVM | Where { $_.Guest.GuestFamily -eq “windowsGuest” }).Count) + ” [Powered off: " + (@($FullVM | Where { $_.Runtime.PowerState -eq "poweredOff" -and $_.Guest.GuestFamily -eq "windowsGuest" }).Count) + "]”
$linuxVM= ” ” + (@($FullVM | Where { $_.Guest.GuestFamily -eq “linuxGuest” }).Count) + ” [Powered off: " + (@($FullVM | Where { $_.Runtime.PowerState -eq "poweredOff" -and $_.Guest.GuestFamily -eq "linuxGuest" }).Count) + "]”
$MyReport += Get-HTMLDetail “Windows VMs:” $windowsVM
$MyReport += Get-HTMLDetail “Linux VMs:” $linuxVM
….
….
### At the end
$runTime=[Math]::Round(($(Get-Date) – $stDate).totalseconds)
send-SMTPmail $EmailTo $EmailFrom “VMWare VIServer $VISRV [Report Runtime $runTime seconds]” $SMTPSRV $MyReport
If you provide some contact, i can email you the complete code. Thank you.
about 6 months ago
Nice script, tested both on VCMS 2.5 and also on vsphere, works well. Wonder if this script can report on more then two VMware vCenter Server Linked Mode environment
Cheers,
about 6 months ago
@Virtu-Al
Nope, no VM’s on local storage at all.
about 6 months ago
My NTP checks isn’t working correctly as I have two listed and this fails. Any ideas on how to get this to work correctly for two ntp servers in the list?
about 6 months ago
@cxo
Glad its all working, dont worry about the SSL warning, its just the same one you would normally get from the VIC when starting that without your certificate enabled.
about 6 months ago
@Mark
They are some nice additions, I will include those definately.
I have tried to keep the output away from the console as the script is designed to run as a scheduled task, 10 mins is pretty good, it takes 45 mins on my production cluster !
So you think I should give some nice output for if people use it from the console ?
Thanks for your comments and additions.
about 6 months ago
@bitsorbytes
Two NTP servers, why didnt I think of that ! – I will have to test that one.
about 6 months ago
@Brandon Yap
Thanks, I think I know what the error is then.
about 6 months ago
@RobSF
I will think about the multipl NTP servers. If you can email me the code I will make sure its the same as what I was using. Thanks for your comments.
Hey, leave something for me to wow people in V3
about 6 months ago
@vishy
Im glad its working for you, more than one VC would need some work but if we wait a while you never know what might happen in the next version of PowerCLI they may include something to make this easier.
about 6 months ago
@Virtu-Al
Great script. Just the right balance of information to include in a “daily” script without making it too overwhelming.
Looking forward to the “local storage VMs” resolution.
I resolved “multiple NTP servers” issue by specifying $ntpserver variable at the top of the script to have servers separated by comma:
$ntpserver = “clock1.domain.com,clock2.domain.com”
Note: make sure it doesn’t have any extra spaces (“clock1, clock2″ is not going to work)
also, in the actual section where the check happens, I modified the following (it’s at the end of that line)
$_.NTPServer -ne $ntpserver
to
[string]::join(“,”,$_.NTPServer) -ne $ntpserver
This combines array of NTP servers into a single text string of comma-separated list of servers, to match how I typed them into the $ntpserver variable.
BTW, my script runs for over an hour: 3 Locations, 78 Hosts, 475 VMs, 59 datastores
I’ll have to code to the script to figure out how long each section takes, as well as the whole script.
about 6 months ago
@Mike
Nice one Mark, thanks, I havent had time to look at it yet but hey, thats great !
I also havent done any performance tweaks, it also takes about 45 mins in our production environment, there are a few performance changes I can make, I may do these in the next version but does it matter that much if its a scheduled task ?
about 6 months ago
Is this ESX4/vSphere specific? I’m drowning in a sea of red text with ESX3/VC2.5
about 6 months ago
Hi Alan, I’m having a few fun an games with the script – seems to crash on the CPU ready section with the following series of errors.
Get-Stat : 8/24/2009 4:00:10 PM Get-Stat 134072FA-071C-4290-A5A3-42538B38
4589 The session is not authenticated.
At E:\Scripts\Daily Reportv2.ps1:611 char:53
+ $myObj.PercReady = [Math]::Round((($v | Get-Stat <<<< -Stat
Cpu.Ready.Summation -RealTime | Where {$_.Instance -eq $cpunum} | Measure-Objec
t -Property Value -Average).Average)/200,1)
about 6 months ago
@Alec: I’m running the v2 script (with a few edits) on two VI 3.5 environments. Specifically, we’re running vCenter 2.5u5 and ESX 3.5u4. And it works great for me!
about 6 months ago
@Mike: Your fix for multiple NTP servers works for me! Thank you very much.
about 6 months ago
@Alec
Having spoken over email I think we have resolved your issues, hopefully as is fine now
about 6 months ago
@Chris
Not sure on that error, will have to look up ‘The session is not authenticated.’ I will see what I can find.
about 6 months ago
I run via scheduler 2 times a day (so unattended). But on instances where i noticed some issues, i try to re-run and seeing something is better then blank cmd window
.
I agree, Run time is not a concern as this is mainly to run from scheduler.
Thanks
about 6 months ago
@Chris,
I also get “Not authenticated” error. I get it twice, so I think it has to be issues with some VMs in the environment. Perhaps there are no statistics available for them. Strange error though.
Add the following just below the “ForEach” line within “CPU %Ready Check” on its own line
$v.Name
It will ouput the name of each VM as it’s being checked. The error should follow VM name. Check if there is anything unusual about the VM. I’ll do the same.
Nothing from this “CPU %Ready Check” section shows up in the report. So I’m not sure if its the problem with the script failing or is my environment clean as far as CPU %Ready.
about 6 months ago
@Virtu-Al
VMKernel log pulls data for only about 1/3 of the servers. Perhaps I should change the number of days to pull from default 1 to a higher number just to see if this is working.
On a separate note, I added output to show amount of time each step takes. There are duplicate Get-VMHost and Get-Datastore commands that can be replaced by an existing variable. That should shave some time off.
prior to general summary stats: 5.3 seconds
after general summary stats: 90.4 seconds
snapshots: 6.5 seconds
datastores: 0.2 seconds
hosts in maint. mode: 0.0 seconds
hosts not responding: 0.0 seconds
new VMs: 14.8 seconds
removed VMs: 2.2 seconds
DRS migrations: 3.3 seconds
VC errors: 1.7 seconds
no VM tools: 0.7 seconds
CDROMs connected: 23.0 seconds
Floppies connected: 16.4 seconds
Local storage VMs: 200.1 seconds
NTP check: 92.1 seconds
CPU %ready: 1011.0 seconds
VC details: 0.7 seconds
VC Event log errors: 2.7 seconds
VC Event log warnings: 2.3 seconds
VMkernel log check: 2219.1 seconds
Total Run time: 61.6 minutes
about 6 months ago
Thanks Mike – I’ll give that a try. The Script still completes , so I assume they are warning messages , but I also dont get any % ready section in the logs.
got another suggestion for v3 for you – looking at numbers of VM’s per datastore ?
about 6 months ago
you are quite right , it only seems to be failing on certain VM’s
possibly out of date VMtools installs as those boxes dont seem to be showing stats in vCenter – vmtools service fallen over perhaps ?
still loving the script a lot though – will have to grab you a beer at the next VMUG
about 6 months ago
Great great script man!
Would it be possible to list the 10 latest deployed vms?
Keep up the good work!
about 6 months ago
Thanks for this wonderful script I keep getting an message specify VI and I am not sure what it is asking for? Should I run this directly through powershell as you can see I am a little lost …………
about 6 months ago
@ZO-US
All you have to do is run the script with a space and then the name of your VC server for example… Dailyreport.ps1 testvcserver
For more info on running this as a scheduled task check here: http://www.virtu-al.net/2009/07/10/running-a-powercli-scheduled-task/
about 6 months ago
@John
Hmmm, do you think that would be more useful than the vm’s created in the previous x days ? Its easily done but I think I will keep it as it is, Don’t worry though I will do a seperate post showing how to get this info so you can add it easily