vCheck (Daily Report)
Introduction
vCheck is a vCenter checking script, the script is designed to run as a scheduled task before you get into the office to present you with key information via an email directly to your inbox in a nice easily readable format.
This script picks on the key known issues and potential issues 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.
This script is not to be confused with an Audit script, I don’t want to remind you that you have 5 hosts and what there names are and how many CPU’s they have each and every day as you don’t want to read that kind of information unless you need it, this script will only tell you about problem areas with your infrastructure.
What is checked for ?
The following items are checked for by default but these can be disabled individually to make the script run faster and remove unwanted items from the report, see “Configuring the script” below for details.
- General Details
- Number of Hosts
- Number of VMs
- Number of Templates
- Number of Clusters
- Number of Datastores
- Number of Active VMs
- Number of Inactive VMs
- Number of DRS Migrations for the last days
- Snapshots over x Days old
- Datastores with less than x% free space
- VMs created over the last x days
- VMs removed over the last x days
- VMs with No Tools
- VMs with CD-Roms connected
- VMs with Floppy Drives Connected
- VMs with CPU ready over x%
- VMs with over x amount of vCPUs
- List of DRS Migrations
- Hosts in Maintenance Mode
- Hosts in disconnected state
- NTP Server check for a given NTP Name
- NTP Service check
- vmkernel warning messages ov the last x days
- VC Error Events over the last x days
- VC Windows Event Log Errors for the last x days with VMware in the details
- VC VMware Service details
- VMs stored on datastores attached to only one host
- VM active alerts
- Cluster Active Alerts
- If HA Cluster is set to use host datastore for swapfile, check the host has a swapfile location set
- Host active Alerts
- Dead SCSI Luns
- VMs with over x amount of vCPUs
- vSphere check: Slot Sizes
- vSphere check: Outdated VM Hardware (Less than V7)
- VMs in Inconsistent folders (the name of the folder is not the same as the name)
- VMs with high CPU usage
- Guest disk size check
- Host over committing memory check
- VM Swap and Ballooning
- ESXi hosts without Lockdown enabled
- ESXi hosts with unsupported mode enabled
- General Capacity information based on CPU/MEM usage of the VMs
- vSwitch free ports
- Disk over commit check
- Host configuration issues
- VCB Garbage (left snapshots)
- HA VM restarts and resets
- Inaccessible VMs
Prerequisites
The following will need to be installed for you to run this script:
- PowerShell V2
- PowerCLU 4.0 U1 or later version
- vCenter 2.5 or later version
Configuring the script
All configuration is stored at the top of the script, it is recommended you check the configuration and change the thresholds before running the script as this will help the script focus on your issues and best practices.
Changing the email information
Just after the comments you will find the following information:
# You can change the following defaults by altering the below settings: # # Set the SMTP Server address $SMTPSRV = "mysmtpserver.mydomain.local" # Set the Email address to recieve from $EmailFrom = "me@mydomain.local" # Set the Email address to send the email to $EmailTo = "me@mydomain.local"
This information will need to be adjusted to your specific requirements in order for the email to work.
If you wish to add multiple recipients then change the $EmailTo to the following:
$EmailTo = “user@domain.com,user2@domain.com"
Setting the thresholds
This will help the script focus on the specific areas you want to report on, it can be used to define your own best practices.
Just after the comments will be a “Detail Settings” part of the script, under here will be a variable for each setting, these are described by a comment before and will need to be changed to fit in with your own specific requirements.
An example is setting the ntp server, to do this change the current setting to match your configuration:
Before
# The NTP server to check $ntpserver = "pool.ntp.org"
After
# The NTP server to check $ntpserver = "ntp.mycompany.mydomainname.internal"
Running the script
The script is currently in “html view mode”, this means that after you have run the script it will display a HTML report with any errors which may be relevent, it is useful to run it in this mode until you are happy with the results, you can then change it to “Email mode”.
To do this, find the area just after you have set the email settings and change the following variables to the required output:
$DisplaytoScreen = $true $SendEmail = $false
To run the script from the PowerCLI prompt simply cd into the folder where the script is located and type the script name followed by your vCenter name as below:
.\vCheck5.ps1 vCenter01
Example:
Customising the report colours
Near the top of the report, just after the version comments will be two areas where you can define custom colours, use these to set the colours of the headings as below:
Main Title bar
$Colour1 = "CC0000"
Check bar
$Colour2 = "7BA7C7"
Adjusting connection information
In some cases you will need to adjust the connection information used by the connect-viserver cmdlet to connect to your vCenter, this can be adjusted on line 701 as below:
Before
$VIServer = Connect-VIServer $VISRV
After
$VIServer = Connect-VIServer $VISRV –user “AlternateUsername” –Pass “Alternatepassword” –Protocol Https
Example report
An example report can be seen by clicking the below image or here, please note that not all checks are triggered here.
Download
Download vCheck 5.0
Downloaded 26774 times












[...] http://www.virtu-al.net/featured-scripts/vcheck/ [...]
Awesome script Alan. I’ve been using it since version one and will use this version from now on. I have found a problem though. If you send the output to e-mail and open the e-mail in Outlook 2007 it does not show the contents of the header and comment lines of each section. If I save the e-mail as .html and open it in Internet Explorer 8 it is ok. This might have to do with the “Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007″. See: http://msdn.microsoft.com/en-us/library/aa338201.aspx. I haven’t found exactly what the problem is yet. But it has probably something to do with the CSS section of the script being not compatible with Outlook 2007.
I also have a suggestion for new features. I would very much like the things included that are in the RVTools vHealth tab and not in vCheck yet. Specially zombie VM’s, zombie vmdk files and zombie templates.
Regards, Robert
I did some more investigation. The problem seems to be that in Office 2007 the background colors are not shown. And you can’t read white letters on a white background. I found a workaround by changing the COLOR: in the .dsp section to #000000, which is black. It still doesn’t look very nice in Office 2007. But now I can read the headers in the e-mail.
Regards, Robert
Hey Alan,
This is a great script with tons of info… Is there going to be an updated powerpack for powergui that will include this vcheck? Also I also manage 3+ VM infrastructure and growing. I would like to also have a copy of the script that can run on multiple VC Infrastructures.
Thanks!
Great script! I see one issue in my small environment in Host overcommiting memory section. There is no numbers in TotalMemMB and TotalUsedMB. TotalAssignedMemMB seems to has a proper value. Eventually I have 2 overcomited hosts.
@Robert-NL
Thanks for the investigation, yes it does look like that, I will have a go at making it compatible whilst also trying to keep the format. …. 5.1 here we come !
Self-correction. Problem with TotalMemMB etc. was due to old version of PowerCli. After U1 upgrade everything is detected properly. Great script just became even greater
@Edward
Yep, there will be an updated PowerPack very soon.
@Pizang
The only time I have seen this before is when people are not running PowerCLI 4.0 U1, have you updated PowerCLI to the latest version ?
Hi Alan, great script
I also have the same problems as Robert, html report in Outlook 2007 isn’t readable as generated file seen in IE. Is it possible to send generated report file as an attachment?
Regards, Aleksandar
Alan,
As I have written after U1 update everything seems to work just great. Maybe you should add some compatibility check to this script?
@Pizang, yeah I was going to but it got to the point where I had added so much I just wanted to get it out
Perhaps 5.1 will include this !
Aleksandar,
Yes you can do that but I think I will see if I can fix it first.
Alan
Looks great though both web and email! Can someone post a sample command line to run as a scheduled task?
I setup the smtp server, and $SendEmail = $ture, but I can’t recevie any email,
Why !!!!
@mtnbiker5
This is the command line we run as a scheduled task:
%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ -command “”
@mntbiker5
The website software cut a piece of the command line. You have to replace the -command “” part with this:
-command “”
@mntbiker5
I now see that the ampersand and curly brackets are special characters for the website software. I try in words:
-command “ampersand curly-brackets-open C:\vCheck.ps1 vCenterServer curly-brackets -close “
@Victor
Looks like the smtp settings are incorrect or you require a secure connection to your smtp server.
I try again, now is ok
[...] To run this you will need to install PowerShell v2 and PowerCLI 4.0 U1 or greater, and vCenter 2.5 or later. For in-depth instructions and the script follow the link. [...]
Great script, but I have a couple of questions…
1) to fix the display issue within outlook, is it possible to have the html file attached to the message instead of embedded?
2) in our environment, we maintain two datacenters within vmware. Is it possible to have this run only for a specific datacenter? I was looking through the code to try and tweak some of the powerCLI stuff, but it looks like you may be using some other method of retrieving the data.
Thanks for the cool script!
Great Work! Unfortunately Capacity Planner Info displays “Estimated Num VM Left (MEM): +infinite (translated, originally +unendlich (german))”. Any idea?
Cheers, Daniel
I have another suggestion for a new feature in the Capacity Planner Info section: Estimated New VM left (Storage).
sorry not sure what you mean, can you send me an email with a screenshot ?
@Robert-NL Good idea
I have the same problem as Daniel has with infinity in the Estimated Num VM Left (MEM). But only on VMware VirtualCenter version 2.5.0 servers. It works ok with a VMware vCenter Server version 4.0.0. I will send you a screenshot with the problem.
I made some investigation and it seems like most of the counters and fields are missing in 2.5 API. I don’t even get (Cluster).Summary
When i run the script with my vserver name, i get an email saying “The Connect-VISERVER Cmdlet did not work, please check you VI Server. ” When I open the vSphere powerCLI i can connect to the same vserver name, but it takes a few seconds due to a certificate warning. I tried making the script wait, but that didn’t help.
What could be wrong? Thanks so much for your work on this.
How long should it take to run? I started at 2:50, at 2:51 it says “..Checking Capacity Info” and almost an hour later its still not progressed.
Thanks, Tuc
@cepelo
I had the same problem. Are you trying to run it twice in same PowerCLI session? If yes, try to close PowerCLI and start vCheck again
Is it possible to specify a single cluster or specific clusters to run the daily check against?
How long is it taking you guys to run this? I was using version 3.0 prior to this, and it would take roughly 1 hour 45 minutes under that version. Version 5 has been running for nearly 4 hours, and still is not finished.
I’ve got about 100 hosts and 1500 VMs.
Update: I eventually killed it after about 7 hours. It was on ‘VM CPU Usage’ and hadn’t progressed in over 2 hours.
I have PowerShell v2, Windows 2K8 x64, vCenter 4.0.0, PowerCLI v4.0 U1. Also I disabled the IE certificate setting that is supposed to speed it up.
Any idea why it is taking so long?
I have another question / request. What would I have to do to add a parameter for a specific datacenter? My environment has 8 datacenters and I would like to break the reports down by datacenter.
No, infact, due to some oddity I rebooted my machine. I eventually had to “false” this and CPU Usage.
Is there a way to find out what didn’t go right?
Thanks, tuc
Are there any plans to add IOPs to the list of data gathered?
[...] Renouf has released v5 of his popular vCheck script (VMware [...]
I am having problems with the NTP setting in this script. I have 2 NTP servers, and no matter how I add them into the script (a single string, comma delimited, as an array, etc…), it still reports all my hosts as wrong.
Am I missing something here?
This script looks great, but unfortunately, I’m getting an error when pulling the ScsiLunPaths:
12:39:20 PM ..Checking Hosts Dead Lun Path
Object reference not set to an instance of an object.
At :line:903 char:26
+ $esxluns = Get-ScsiLun <<<< -vmhost $esxhost |Get-ScsiLunPath
The host it's erroring out on is a boot-from-san ESXi 4.0 U1 host (in case that makes a difference)
In my testing, it looks as though the outlook issue may be related to the using two classes for some of the HTML elements. I am thinking that outlook does not like this.
For example, in the Function Get-CustomHeader0, there is the header tag with the CSS class defined as class=”dsp dsphead0″. This is perfectly acceptable, and basically says to the HTML parser that there are to CSS classes for this element. If any rules overlap between the two the class that is defined last will take precedence.
I took the definition of dsp and pasted it into the dentition’s for dsphead0 and dsphead1. After this, my outlook HTML was better. The colors were correct, but the fonts, sizing and placement are a little off. I will play around with it some more as time allows and if I find anything, i will post here.
Thanks!
@Ed
To test for two ntp servers you have to do it like this:
$ntpserver = “ntp1.domain.nl|ntp2.domain.nl”
I know im doing something done, but I keep getting “The Connect-VISERVER Cmdlet did not work, please check you VI Server ” when i try to invoke the script
The disk overallocation % doesnt show up in the report.
Found this missing from the task enablement section:
# Show Over Allocation
$ShowOverAllocation = $true
I was able to get the file attached by modifying the following function.
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body, $attachment) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$msg.IsBodyHTML = $true
$attachment = new-object Net.Mail.Attachment($attachment)
$msg.attachments.add($attachment)
$mailer.send($msg)
}
and then changing the $sendmail output.
if ($SendEmail) {
Write-CustomOut “..Sending Email”
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV $MyReport $Filename
}
Can anyone let me know how long does it takes you to run this? If you can include how many VMs and hosts you have that would be helpful.
I can’t get the script to run in less than 8 hours.
Thanks.
I run vCheck in three environments. I will show the times for all three:
Environment 1, hosts 2, VMs 12, time 0 hours 14 minutes
Environment 2, hosts 16, VMs 163, time 1 hour 20 minutes
Environment 3, hosts 13, VMs 120, time 2 hours 34 minutes
We have 2 environments.
Environment 1, 9 hosts, 103 vm’s, 27 minutes
Environment 2, 7 hosts, 22 vm’s, 17 minutes
Found this missing from the task enablement section:
# VCB garbage
$ShowVCBGarbage = $true
Does anyone know how to get IOPs information added to the report?
Thanks
Is there a way to list alarms that have triggered in the last 24 hrs?
A possible addition for version 5.1 – a check for VMs with resource limits attached. Sometimes if you P2V a system, resource limits will automatically apply, which can cripple any potential performance gains.
# —- Resource Limit Check —-
If ($ShowResourceLimits){
Write-CustomOut “..Checking for Resource Limits”
$VMResourceLimits = @(get-vm | get-view | where {$_.ResourceConfig.CpuAllocation.Limit -ne -1 -or $_.ResourceConfig.MemoryAllocation.Limit -ne -1} | Select Name, @{N=”CPULimit”;E={$_.ResourceConfig.CpuAllocation.Limit}}, @{N=”MEMLimit”;E={$_.ResourceConfig.MemoryAllocation.Limit}} | Sort Name)
If (($VMResourceLimits | Measure-Object).count -gt 0){
$MyReport += Get-CustomHeader “Number of VMs with resource limits : $($VMResourceLimits.count)” “VMs with Resource limits”
$MyReport += Get-HTMLTable $VMResourceLimits
$MyReport += Get-CustomHeaderClose
}
}
Consider replacing:
Function Get-HTMLTable {
param([array]$Content)
$HTMLTable = $Content | ConvertTo-Html
With:
Function Get-HTMLTable {
param([array]$Content)
$HTMLTable = $Content | ConvertTo-Html -Fragment
This may reduce the number of “-replace” operations required.
- Simon
RE scheduled task – Is there a certain directory I should run the script from (the first time?) to properly set the crd file? I am able to get the script to run sucessfully from the command line, but from scheduled task it just hangs. I have tried the myriad ways described above.
It says that the running task is ‘powershell.exe’ but I don’t see a connection inside vSphere until after I ‘end’ the task.
Am I missing something?
Thanks.
Fixed my own problem:
I needed to change $CredFile = “.\mycred.crd” to an absolute directory: $CredFile = “c:\vCheck\mycred.crd” and it worked perfectly.
This script is great; thanks so much.
Love this site. I came to v5 in a round about way since I discovered you via google search. I had a terrible time finding the download link for this vCheck tool. Is that by design? Is it possible to add a link to the master lay out that sends you directly to the Download page?
Estimated Num VM Left is showing infinity. Why is that?
Hi seems when i run the script in email mode it does not have any headers generated as compared to the report generated in html view mode
Hello, I am getting the following error when running the script…Anyone else has this issue?
How did you fix it? Thank you
Missing file specification after redirection operator.
At :line:250 char:102
+ <<<<
I am experiencing the same issue at #6, where there are no headers for each section in email mode.
Any tips on excluding specific mount points or drives from the Guests with Less than xxxMB. For example, I would like to exclude all /boot mount points from the check.
Thanks,
Paul
Had the same issue with capacity planner listing infinite VM’s left.
Found this was caused by the counter – $CluMemUsage – not having a value hence causing a divisable by 0 situation making the final value infinity.
This was caused by the counter – mem.consumed.average – not being enabled by default at Statistics Level 1 in the VC Management Sever Configuration (under the Administration menu in the VC) changing this to Level 2 for Days & Weeks enabled the counter for the required period in the script and this now returns a proper value for capacity.
I’m running VC 2.5 and making the above change fixed my issue I think this counter maybe enabled by default in vSphere? So may not be the fix for this.
For Kevin & Paul with the missing headers issue, I have changed the font color under .dsp from FFFFFF (White) to 000000 (Black) so the text now shows up. When the issue is resolved I plan on changing back to white but for now it works and I can see them.
looks like Line 1304
$Details = “” | Select-Object Name, Message
should be:
$Details = “” | Select-Object Name, Message, Reason
I really enjoy using this script as a base for my daily audits, but one thing I’d like to have added (so I don’t have to do it myself after each update) is the ability to set an array to limit scope to particular containers. I have folders, datacenters, and clusters that have varied administrative groups so limiting the report details to their systems is vital.
Loyus Notes 6.x also fails to diskplay the report nicely.
@shartma. Thanks for the e-mail attachment code. Just one comment, You MUST set $DisplaytoScreen = $true otherwise the attachment is not created therefore cannot be sent
Another quick and dirty way is to add the report generating code to the send mail section.
if ($SendEmail) {
Write-CustomOut “..Sending Email”
if (-not (test-path E:\temp\)){
MD E:\temp | Out-Null
}
$Filename = “E:\temp\” + $VIServer + “vCheck” + “_” + $Date.Day + “-” + $Date.Month + “-” + $Date.Year + “.htm”
$MyReport | out-file -encoding ASCII -filepath $Filename
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV $MyReport $Filename
}
I love this script! I run it every night and review the output in the morning. I recently shared the link with some co-workers and they had suggestions. The good news — the script already checks for what they wanted. The output excludes any check where 0 results were returned. Would it be possible to add a setting that would allow all executed checks to appear in the report — even if no results were returned?
Can anyone help with this issue? Thank you, Rene
Missing file specification after redirection operator.
At C:\DOCUME~1\user\LOCALS~1\Temp\5e580c66-6ad6-40be-afb0-6a0974d0faa2.ps1:25
0 char:102
+ <<<
Thanks Mark the colour change works great.
Is there a specific reason why you use
705: $APPPATH = “C:\Documents and Settings\” + $USER + “\Application Data”
Instead of just %appdata%?
I chose to go with an attachment like shartma but did not want a copy of report in body so I changed:
if ($SendEmail) {
Write-CustomOut “..Sending Email”
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV $MyReport $Filename
}
to:
if ($SendEmail) {
Write-CustomOut “..Sending Email”
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV “vCheck report for $VISRV is attached” $Filename
}
I would like to run this script based on the folder level or datacenter level anyone doing this or does anyone have any suggestions
I was wondering if this script could add a check for the following information:
host connected serial ports
host connected parallel ports
number of LUNs per cluster
I have found when server admins do a p2v the leave serial and parallel ports connected causing DRS or vmotions to fail just like floppies and CDROMs do.
This has been a great utility. The universe owes you a ton of good karma for creating it.
Thanks,
Jon
A great idea… already have a ton of features for the next version. Thanks for the addition.
when i set this script as a scheduled task in windows 2k3, it runs but when it gets to the last few services it prompts for a password, I type it in thinking it will save it in the mycred.crd file but it prompts everytime. I have validated that the credentials are correct. I tried specifying also a different path in the vCheck file for where the .crd file is located. Still no luck. I also tried recreating the .crd file and that did not solve it. I am giving a user with Domain Admin rights as well when it prompts for the vmconsole. Any help would be great. Great script!
[...] NetWrix’s Change Reporter for VMware. A final free (and nothing short of awesome) tool is Alan Renouf’s vCheck Daily Report PowerShell Script.Do you have free tools, scripts or utilities for your VMware environment? I’d love to hear [...]
I’m trying to setup the script to run as a scheduled task and it keeps failing to run.
The contents of the batch file is:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ “& ‘C:\Temp\Daily_Scripts\vCheck5.ps1′”DFCU-PVC01
The error I am getting is:
The term ‘param’ is not recognized as the name of a cmdlet, function, script fi
le, or operable program. Check the spelling of the name, or if a path was inclu
ded, verify that the path is correct and try again.
At C:\Temp\Daily_Scripts\vCheck5.ps1:3 char:6
+ param <<<< ( [string] $VISRV)
+ CategoryInfo : ObjectNotFound: (param:String) [], CommandNotFou
ndException
+ FullyQualifiedErrorId : CommandNotFoundException
Nice Script. But how to check more than one NTP-Server? Our ESX use two TimeServers. I tried to add them with comma and space seperated. Even if I enter only one of them, I allways get an error from your script.
How can I tell if it is running and what % it has completed? I have small environment with about 6 ESX hosts and around 50 virtual machines and I have yet to see anything and it’s been running for about 1 hour or so?
Nice job on this BTW!
First of all, this is really a great tool / check
As far as I can tell I’ve run into 3 minor issues. Two of them are related to a fault-tolerant guest (at least I think so).
The vCheck gives us some empty results. I think this is because of the secondary VM with the same name.
It tells us the VM has less then 10 MB of diskspace left (and shows only the name of the machine)
and it tells us this machine has a VM Tools issue. Again no additinal details are shown (only the guest name).
and one general for the NTP check. We’ve gotten multiple NTP Servers and then it doesn’t think it is complient. Is there a special way to tell the script it should check for 2 or more NTP servers or is this not (yet) part of the check logic?
@Andreas
From an earlier post:
To test for two ntp servers you have to do it like this:
$ntpserver = “ntp1.domain.nl|ntp2.domain.nl”
I just wanted to say thank you and to all the folks who worked on this script it great. It will not only help me in administration of my VM’s but it will also help me in better understanding and learning PowerShell. I am pushing myself to learn Ps with this script I can use it as a example. You did a lot of great work on this and it goes to show what can be done with PS.
Thanks Rich
@Mark
Thank you for the info. Tested and working
@dsammich
You can put a “cmd /c” in front of the scheduled task and and append somthing like “>vcheck.log”. Then you can see what your script is doing.
I’ve done this and my script was stopping at the “vCenter Services check”. The Problem was that the Task was running as a lokal admin user. After changing to a Domain Admin User the script was running fine.
@bryan & @Andreas
I had the same issue of the script prompting for the password.
What I had done was to create a local account on the vCenter cerver for the script to use BUT I had forgotten to grant that use any rights in vCenter itself.
Once the rights were granted the script ran fine. The only thing I now need to do is work out what rights it needs so that I can reduce it to the bare minimum..
@dsammich
)
We also have a similar sized environment an it takes about 15 minutes to run.
Another alternative to Andreas’s solution is to start a command prompt as the user that the script will run using runas, then run the same command as specified in the Schedule. Once you get that working then start on the scheduled task.
I know it sounds silly but Its so easy to forget to test the script as the user that the Scheduled taks is running as… (one dunce here
runas is a nice idea. But don’t forget to cd (change directory) to the same folder as defined in the scheduled task under “Start in” or your stored credentials file will be in the wrong place.
Dude, I’ve been listening to get-scripting and decided to come check out your script. This is insanely good and useful.
Thanks so much.
Another thing that would be nice to check is the status of VMTools installations.
With Linux systems it is easy to forget to end the installation mode and until then the VM cannot be migrated.
This is great -all runs smooth just one problem that i am experiencing – i get this error “WARNING: Unable to populate snapshot size due to insufficient permissions” – any thoughts ?
When I run script I receive this message:
The Connect-VISERVER Cmdlet did not work, please check you VI Server.
Thanks for this Script. This works like an absolute beauty.
Here is a link that goes over the HTML rendering limitations for Word 2007 (aka Outlook 2007). It includes a testing tool also.
http://msdn.microsoft.com/en-us/library/aa338201(office.12).aspx
That is a nice reference, thanks for that, I will make sure I run the next version through there first.
Top script Alan use it manually and works a treat. Having issues getting it running as a scheduled task. It asks for the creds which I put in and goes through but comes through to mail saying the connect-vi server cmdlet did not work please check you VI Server
I know the VI-Server is correct as I get it working direct from vSphere Power CLI, I know i must be missing something simple here but lost HELP please.
We were getting a lot of linux guests reporting on low disk space for /boot so we decided to clean up and remove /boot from the checks by changing:
Foreach ($disk in $VMdsk.Guest.Disk){
if (([math]::Round($disk.Capacity/ 1MB)) -lt $MBFree){
To this:
Foreach ($disk in $VMdsk.Guest.Disk){
if (([math]::Round($disk.Capacity/ 1MB)) -lt $MBFree -and $Disk.DiskPath -ne “/boot”){
[...] See comment on the publishers site here [...]
Another approach is to check for free MB AND free %:
Foreach ($disk in $VMdsk.Guest.Disk){
$dskPercFree = [math]::Round($disk.Freespace/$disk.Capacity, 2) * 100
if ((([math]::Round($disk.FreeSpace/ 1MB)) -lt $MBFree) -and ($dskPercFree -lt ($PercFree))){
Does anyone know how to automatically connect to your VC server “$VISRV”. Where would you place the name of the Virtual Centre Server in the script as V5 as is won’t run as a scheduled task??
@Luca Check my answer in the PowerCLI forums: http://communities.vmware.com/thread/270791?tstart=0
I have created a windows scheduled task with the following run line: %SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1″ -command “” it does not seem to do anything when run?? any ideas?
All of my Solaris guests show that they have no disk space free, although this isn’t the case. They use ZFS root.
“WARNING: Unable to populate snapshot size due to insufficient permissions” … I too get this error on some vm snapshots in the “Checking Snapshots” routine. Problem seems to be just snapshots on vm’s configured with multiple vdisk located on different datastores. Snapshots on vm’s configured with single vdisk or mult vdisk on same datastore produce no error. I have admin rights and can browse all datastores.
Great script. Thank you. I am interested in also getting overall LUN Disk space usage as an informational value. Another thing – it shows the VM Hardware version as 4 for me, but I would also like to see which ones are on 7 already.
Hi – Firstly – Fantastic script – I have learnt a huge amount just following this thread!.
Here’s my issue (sorry!) – I hve a number of VM’s with a C:\ of less than 500mb – So, I set the threshold to 700 – nothing comes up – But I noticed that the D:\ of the VM’s in question have GB’s of space – Does the VM space check report per volume or in total??? – If I make the freshold 400000 then it reports everything (which is what I would expect) – can anyone let me know what I may be doing wrong? Cheers
I have updated vcheck5 to user powershell v5 advanced parameters instead of all the variables set at the top of the script. This will allows for better long term maintenance for everyone using the script. Thus everyone does not have to edit the new script when it comes out. They should be able to pop it in, possibly adding new switches for the new features only. Email me if you are interested.
Sounds great, can you email them to me so I can see what you have done, I have a few good ideas for this myself but would be interested in what you have done.
Is it possbile to have the html report only capture issue or misconfigurations? As more functionality is added to the script I can see myself scrolling through the full report looking for warning or issues only.
Are you pointing this at your vCenter server or a host? I’m having trouble, I get an error:
The Connect-VISERVER Cmdlet did not work, please check you VI Server.
We’re running vSphere 4. Does it need to be run on the vCenter server itself?
Oh wait, no panic. As we’re working with MSSCCM at the moment, I’d forgotten to reinstall a necessary component on my PC (using it for testing so was rebuilt).
Thanks!
Did you get my email with the modifies script?
Hey Al,
Would it be possible to include the option to exclude snapshots with a certain name? i.e replica_*
We use your report on View environments and the report is constantly reporting the View snapshots.
Thanks.
[...] Alan Renouf’s vCheck Daily Report – Another Powershell script that reports on a large number of areas within the virtual infrastructure. One of those areas includes snapshots [...]
Has anyone figured out a way to make this render properly in Outlook 2007/2010? I’m using the latest version of the script and I see the comment where you can modify the COLOR: to black so that it displays properly. I confirmed mine is set that way and I still cannot view this in Outlook.
It looks great as HTML. Someone else had the suggestion of providing an option to just attach it as an HTML file. Is that possible?
Or you can actually modify the correct part of the script to make it work. I can confirm that the workaround does in fact work.. Sorry about that.
Matt, I am having the same issue in Outlook. What did you modify to make it viewable in Outlook? Thanks
I read other posts here and by changing the font color under .dsp from FFFFFF (White) to 000000 (Black) the text now shows up great in Outlook.
In PowerShell V2 the ConvertTo-Html cmdlet has a -Fragment parameter that “Generates only an HTML table. The HTML, HEAD, TITLE, and BODY tags are omitted.”. I don’t know if this parameter is present in PowerShell V1. With the -Fragment parameter you can rewrite the Get-HTMLTable function into:
Function Get-HTMLTable {
param([array]$Content)
$HTMLTable = $Content | ConvertTo-Html -Fragment
Return $HTMLTable
}
I tried running the script, but it’s been at “…Checking capacity info” for more than 40 minutes now. Is this normal?
Thanks,
Kris
Is there a way to have the html report added as a ‘tab’ within VCenter?
You read my mind
yes there is, you can actually use my plugin generator script to add this and just amend the code so it creates the same html page each time.
love this script. been using it for some time but noticed it hangs on ” ..Checking Snapshots” section, even if left for hours. it there any way to tell what it might be hung up on?
thanks.
There is a problem with the get-snapshot cmdlet in the current release, look out soon on the vmware site for a new version of PowerCLI
Hi, There
your script is great. I have been using it for the last week.
I would like to make a suggestion. Under the snapshots section I would be nice if we could get the amount in MB of the autual size of the snapshots.
Right now we only get the total amount of disk size
I am having some issues.
What happens is that i am not able to get the script running.
It says “connection to VI server” for a few seconds and then comes back to the command prompt. I do not find any HTML report.
I have set all things correctly as i know. These are :
1. Setting done to make the report display on screen.
2. Setting done to enter my username in the script that would be used to connect to the virtualcenter server.
Please help.
Best Regards
Vincent S
I am trying this on another virtualcenter server and i get a message saying “the script is not digitally signed and so it will not run”.
Please help.
Is v5 only for vSphere? I have been using v3 with VI 3.5 with no problem but with v5, I am getting math errors. I am using ps2 and the latest PowerCLI.
Attempted to divide by zero.
At :line:571 char:73
+ $MyDetails.PercFreeSpace = [math]::Round(((100 * ($ds.FreeSpaceMB)) / <<<< ($ds.CapacityMB)),0)
Yes, the display of this report in Outlook 2007 is a pain. The table borders all show up with no content. Would it be possible to add the font color as a variable, and perhaps use that -fragment function for the HTML output? Otherwise this script works fantastic for us…thanks Al!
One more item. Would it be possible to check to see if the host is reporting hardware sensor info? There have been a few times where for whatever reason, the host doesn’t report this, and it does not raise an alert in vCenter. Then you try to run VUM and it won’t work properly because it can’t detect the power state of one of your hosts. This would be a big help!
to shoh is tools need to be updated.
Add this to turn on in the correct section
$Showtoolsupdate = true
Then add
# —- VM Tools update —-
If ($Showtoolsupdate){
Write-CustomOut “..Checking VM Tools Out of Date”
$UpdateTools = @($FullVM |Where {$_.Guest.ToolsStatus -eq “ToolsOld”} |Select Name, @{N=”Status”;E={$_.Guest.ToolsStatus}})
If (($UpdateTools | Measure-Object).count -gt 0) {
$MyReport += Get-CustomHeader “VM Tools Updates : $($UpdateTools.count)” “The following VMs have issues with VMtools and need to be updated”
$MyReport += Get-HTMLTable $UpdateTools
$MyReport += Get-CustomHeaderClose
}
}
To show if tools need to be updated.
Add this to turn on in the correct section
$Showtoolsupdate = true
Then add
# —- VM Tools update —-
If ($Showtoolsupdate){
Write-CustomOut “..Checking VM Tools Out of Date”
$UpdateTools = @($FullVM |Where {$_.Guest.ToolsStatus -eq “ToolsOld”} |Select Name, @{N=”Status”;E={$_.Guest.ToolsStatus}})
If (($UpdateTools | Measure-Object).count -gt 0) {
$MyReport += Get-CustomHeader “VM Tools Updates : $($UpdateTools.count)” “The following VMs have issues with VMtools and need to be updated”
$MyReport += Get-HTMLTable $UpdateTools
$MyReport += Get-CustomHeaderClose
}
}
Kevin,
Should the $Showtoolsupdate = true be $Showtoolsupdate = $true
Hi!
thanks for this great report. i’m using it since version 3.
now i have updated it to v5 but still now i have issues with it.
it seems that the report is only generating only cluster in vcenter (only 5 from 70 hosts) so the report not finished.
on excecuting there are no errors within runtime of the script.
do you have some ideas?
Whilst updating our servers to v4.1 I had a thought
It would be nice if the vCheck script could indicate which version the Hosts are running. Maybe have something that would show the highest version used in the cluster and which machines are not at that revision.
That way you would not have to keep updating the script with which version you want to check for. Maybe that should be an option as well for those who want tighter control.
I recently started testing this version, having used version 1.2 for a while now.
Amazing work, however this one seems to take about 5 hours on the capacity info check, and then had some memory failure issues when checking snapshots.
Have you seen this before?
does the script re-prompt for credentials on the vCenter services and event log sections for anyone else? i even tried to hard code in the -user and – password fields to no avail.
[...] come down for hardware repairs, I removed it from the cluster so it wouldn’t show up on my vCheck reports. Upon attempting to add the server back I received a pop-up from the vCenter client with [...]
can someone suggest me how can i run this script using task schedular? this script requires user Intervention to provide user account details.
can we use stored creds in .xml file and run the sript in schedules?
We can able to see Letters in black in Outlook but background is Missing…. If background cloour also come.. it will look gr8.
Any suggestions pls.
All,
I run this script for ESX server.. it is showing Host minimal info and VM /DB info.. but am looking for a report which include below info of ESX server. Can some one please see below and help me if any script available.
1. ESX Partiton info
2. Root password age notification
3. Esx current patch level / updates
4. VMKernal errors
5. ESX uptime
6. ESX Hardware issues
7. Security Warnings
iF We can able to get the above info, easily we can able to administer ESX server. That report should have only issues not the information like vCheck5.ps1
PLEASE HELP ME IS ANY ONE HAS LIKE THAT
Statement correction:
iF We can able to get the above info, easily we can able to administer ESX server. That report should have only issues not the information like vCheck5.ps1
###########################################################
iF We can able to get the above info, easily we can able to administer ESX server. That report should have only issues like vCheck5.ps1 not the information of ESX like other Daily health check scripts…
[...] This post was mentioned on Twitter by Pumpith Ungsupanit, Pumpith Ungsupanit. Pumpith Ungsupanit said: Comments for Virtu-Al – vCheck (Daily Report) | Virtu-Al http://bit.ly/dtwIqD [...]
Great script. I would like to make a suggestion for a future enhancement. Can you split the HTML and SmtpMail functions into their own module or ps1 file so that it can be imported into a session and used by other scripts. I have used your functions to build other HTML reports and would like to keep up with any enhancements to it in the furture without having to dowonload the script and remove the rest of the script.
Hi,
Your script is amazing and very useful
In my environment we have a lot of lab VM’s with many snapshots.
I would like to exclude them from the snapshot report.
Is it possible to exclude a list of VM’s not to report on, similar to the $LVMDoNotInclude = “Template_*|VDI*” variable?
Yes, please correct the base script so the HTLM renders properly in Outlook 2007/2010. Also, can you test against 4.1? Looks great!
Here’s what I had to do to get v5 to work as a scheduled task with Windows 2008 R2.
Problem – The script would not run as a scheduled task. It would run from the command line.
Solution – Manually run the script from command line so it creates the .CRD file. Then modify $CredFile so it has the full path to the .crd file.
Feature request:
- Add “Top 10″ VMs with highest read IOPS and write IOPS
- Add “Top 10″ VMs with highest read latency and write latency
- In the prediction report – have the report include average VM disk size in the calculations.
- Add a section for Host hardware status alerts
Al,
Thanks for a great script. I have to admit though that I have not used it in its native form, but have shamelessly plagerised the pieces I need for my scripts. I have taken a slightly different tack (read diametrically opposite) to you with your health check script. I have created a single folder with a number of small scripts that do various pieces: some report on disk space to the SAN administrator, some report machine creation to the Infrastructure Manager and one of them even trawls logs, events and VM properties for information to include in custom fields in vCenter. This folder in itself simply becomes the scheduled task by running powershell across the folder using the following command : “Get-ChildItem *.ps1 | Invoke-Expression”. Works for me anyway and Thanks.
Derrick
It would be great if we could see the actual snapshot size other than whole disk size. Is this a feature?
Anyone have any issues with how the report shows in outlook? I can’t see the description of each report. The box is blank. It shows fine when I run the script and it just saves the htm file.
[...] the help of Alan Renouf’s vCheck (Daily Report) script I recently started noticing an error in my Windows event log on a vCenter [...]
The problem with Outlook are well documented in the past 40 posts.
The easy way to make it work in Outlook, is click the link at the top of the page that says “View in Browser”.
But that brings up another feature request:
- add the ability to save the report to a directory.
- attach the report as an html file to email.
It would be really nice if the reports could be stored on a network share, then the script sends an email saying when the report is ready.
At the end of the script there already is code to save the file to a location. You just have uncomment the lines similar to this:
__________________________________________________________________
#Uncomment the following lines to save the htm file in a central location
if ($DisplayToScreen) {
Write-CustomOut “..Displaying HTML results”
if (-not (test-path c:\tmp\)){
MD c:\tmp | Out-Null
}
$Filename = “C:\Reports\” + $VIServer + “_DailyReport” + “_” + (Get-Date -format yyyy-MM-dd) + “.htm”
$MyReport | out-file -encoding ASCII -filepath $Filename
Invoke-Item $Filename
}
if ($SendEmail) {
Write-CustomOut “..Sending Email”
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV $MyReport
____________________________________________________________________
I send the output to file in the Reports folder & e-mail daily so I can review it at a later date if needed without keeping the e-mails.
Hope this helps…
Mark
Hello I am running this from the VC locally and it runs through fine (takes about 15 minutes) but the html output consistently shows that it found only 1 host, 1 datastore, 1 VM, etc. I am not sure where else to look…it is running under my user context. The box is a 2008 box and I have tried to run it under the CLI in administrator mode and regular mode. I have the scripts folder on the F: drive so I am just entering the full path to the script with a space and the VC name at the CLI command prompt. Anything come into mind that I might be doing wrong?
Very nice script. I can see how this will be very useful to us in the future. What are you using to determine the capacity recommendations?
How do you set up a automatic script to run the command every day? It works doing the manual script when in the vSphere PowerCLI.
Alan,
Great script and it’s provided me some excellent information over the last few hours that I wouldn’t otherwise have gotten.
I’m running into two problems though:
The first one is that it complains about some sort of root certificate issue which I’m sure is just a powershell issue so I’ll look into that next but if you have any ideas I’d would greatly appreciate it.
The second problem I have is that I get the following error message when vCheck5.ps1 does the Snapshot Check:
“WARNING: Unable to populate snapshot size due to unsiffucient permissions.”
I noticed when going through the comments that I should look at upgrading the PowerCLI 4.1 to get the snapshot stuff working which I did and I’m running the script with my credentials which have Administrator access to Virtual Center so I’m a bit at a loss as to what’s going on. The ESX environment is ESX 3.5.0, 153875 and Virtual Center is version 2.5.0 Build 147633. The only thing I haven’t done is update the ESX environment which is something I can’t do at the moment due to project restrictions.
Any suggestions would be welcome.
Thanks,
Bryan
hi,
for the love of god i can’t get the script to run under windows 2008 R2 using the Task Scheduler.
any help would be kindly appreciated.
This is the batch file i’m trying to run. if i right click on the batch file, the script runs beautifully, but not under the Task Scheduler.
————————-
powershell.exe -PSConsoleFile “vim.psc1″ ” & “.\vCheck.ps1″ vcenter01
———————————–
i have a credential file, but i keep getting a powershell credential request asking for user name and password. after entering the user credential, i see the report.
Thanks
Dan
This script is great and very cleanly written and well commented. You know your stuff.
Feature Requests:
1. Allow a comma seperated list of virtual center servers. I have multiple.
2. allow the settings to be changed via cmdline switch. for example i may want to suppress certain part of the reports and only show them once a week.
[...] took the wonderful vcheck script and made it run every night. Great email overview of the virtual infrastructure each [...]
I changed below to send report as attachment as Outlook 2007/10 use Word to render HTML and not IE.
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body, $attachment) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$msg.IsBodyHTML = $true
$attachment = new-object Net.Mail.Attachment($attachment)
$msg.attachments.add($attachment)
$mailer.send($msg)
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV -body “$VISRV vCheck Report” -attachment “$Filename”
Hi!
First, THANKS for this great great script!!!
What about PortGroups? There exists a command to view this object? Deleted, Added, and so on…
Thanks again!
Great script, but quick question with regards to rights required to run this.
What rights will the virtual center user require to run the script without just giving it Administrator?
Thanks
David
Hi
This script is awsome and works great in our enviornment. Thanks for your script.
One of the Heading in the scripts says number of Inactive machines.
What exactly it means that the machines are turned of or what.
Secondly it doesnt list those VM’s. Can i have code for that please.
Regards
Anubhav
I’m trying to get this running again now that I’ve upgraded to vCentre 4.1 on Windows 2008. I’ve created a batchfile that contains the following:
%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ -command “-close”
I’ve also got the
add-pssnapin VMware.VimAutomation.Core
line in my PS1 file as suggested elsewhere on this site.
It runs perfectly if I run the batchfile interactively, but as a scheduled task, it does nothing – Powershell seems to start up (I can see the process in Task Manager) but I never get an e-mail and the task doesn’t end.
Any suggestions?
Apologies…. the command above should read
%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ -command “ampersand(curly brackets open)C:\Batch\VMCheck5.ps1 vCentre(curly brackets close) -close”
it appears that ampersands or curly brackets – or both – are not liked by the commenting system – so they got chopped out first time!
This works for me when scheduled to run locally on the vSphere server. The account details to connectt to vsphere are in the vcheck.ps1 fiel aswell
C:\WINDOWS\SYSTEM32\windowspowershell\v1.0\powershell.exe -psc “C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ -noe “& ‘C:\tools\scripts\vCheck5.ps1′” INF-vCenter
Hi,
I keep getting an error when it’s checking tech support mode against hosts in my vCenter:
‘VMkernel.Boot.techSupportMode’ is invalid or exceeds the maximum number of characters permitted.
Line in script:
$ESXiTechMode = $VMH | Where {$_.State -eq “Connected” -or $_.State -eq “Maintenance”} | Get-View | Where {$_.Summary.Config.Product.Name -match “i”} | Select Name, @{N=”TechSuportModeEnabled”;E={(Get-VMHost $_.Name | Get-VMHostAdvancedConfiguration <<<< -Name VMkernel.Boot.techSupportMode).values}}
Anyone else come across this?
Thanks, Ross
[...] Licenčná politika je rovnaká, ako pre väčšinu produktov VMware – licencie sa nakupujú na procesor (socket), pričom cena jednej licencie aj s production support & subscription vychádza na zhruba 500 EUR. Ak hľadáte cenovo menej náročnú alternatívu, môžete vyskúšať nástroj vCheck, ktorý je k dispozícii zdarma. Sťahovať ho môžete tu [...]
Hello,
it would be nice if there was a check for SCSI LUNS with only one path.
In our environment, all the path must be redundant. But we can not avoid a mistake from the storage team. So if we could have a check that verifies the number of path of each LUNs (this number could be a parameter). If the number is less than the parameter, then it appears in the reporting.
Thanks,
David
Great job on this script, Al. Very well done.
Curious – I have iniated the script which i kicked off @ 8:33 PM EST. It is now 10:52 PM EST and it is still at Checking capacity info.. Its been on the capacity part since 8:41PM.. Is it because my environment is large or is something hanging. I do see HD activity.
What are the minimum rights the account running the script requires on the vSphere server?
When I say vSphere, I mean vCenter!
“”"What are the minimum rights the account running the script requires on the vSphere server?”"”
I had the same issue, my server is 64-bit Windows 2008 R2 and vCenter 4.1 and had issues trying to get the script to run on the vCenter server locally. I tried:
Made sure UAC was disabled
Made sure RemoteSigned policy was enabled
Made sure my account was an Administrator on the server and in vCenter
Ran command in PowerShell (32-bit) both as my account and “Run as administrator”
Ran command in PowerShell (64-bit) both as my account and “Run as administrator”
Ran command in VMware vSphere PowerCLI (32-bit) both as my account and “Run as administrator”
Ran command in VMware vSphere PowerCLI (64-bit) both as my account and “Run as administrator”
Each time I made sure to use the vCenter server and used several variations like WINs name, FQDN, localhost, and IP.
I was never able to get the script to report more than 1 host even though I have 18 in vCenter.
Only way I got this to work was to run the script remotely from my Windows 7 32-Bit VM.
I am also having the “WARNING: Unable to populate snapshot size due to ‘unsiffucient’ permissions.” despite having the appropriate permissions and running PowerCLI v4.1 – I have cleanly installed everything to a new machine and attempted to run it from there with exactly the same results – Help would be appreciated with this.
If you want the script to use the credentials you supply that are stored in the mycred.crd change the lines 701 and 712 that read
$VIServer = Connect-VIServer $VISRV
to
$VIServer = Connect-VIServer $VISRV -cred $creds
Found this sript took a long time to run but once completed highlighted a number of issues with our environment which we were previously unaware.
A must for any VMware Administrator.
Mine is also stuck at checking capacity info and has been for a long time. A bug maybe?
The following is code I wrote for just checking the free space of the C:\ drive. Enjoy.
Top Section
# Show VMs C:\ disk space check
$ShowGuestCDriveSpace = $true
Code Section:
# —- VM Disk Space – C: \ Less than x MB —-
If ($ShowGuestCDriveSpace){
Write-CustomOut “..Checking for Guests with C:\ less than $MBFree MB”
$MyCollection = @()
$AllVMs = $FullVM | Where {-not $_.Config.Template } | Where { $_.Runtime.PowerState -eq “poweredOn” -And ($_.Guest.toolsStatus -ne “toolsNotInstalled” -And $_.Guest.ToolsStatus -ne “toolsNotRunning”)}
$SortedVMs = $AllVMs | Select *, @{N=”NumDisks”;E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
ForEach ($VMdsk in $SortedVMs){
$Details = New-object PSObject
$DiskNum = 0
Foreach ($disk in $VMdsk.Guest.Disk){
if ($disk.DiskPath -eq “c:\” ){
if (([math]::Round($disk.FreeSpace / 1MB)) -lt $MBFree){
$Details | Add-Member -Name Name -Value $VMdsk.name -Membertype NoteProperty
$Details | Add-Member -Name “Disk$($DiskNum)path” -MemberType NoteProperty -Value $Disk.DiskPath
$Details | Add-Member -Name “Disk$($DiskNum)Capacity(MB)” -MemberType NoteProperty -Value ([math]::Round($disk.Capacity/ 1MB))
$Details | Add-Member -Name “Disk$($DiskNum)FreeSpace(MB)” -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1MB))
$DiskNum++
$MyCollection += $Details
}
}
}
}
If (($MyCollection | Measure-Object).count -gt 0) {
$MyReport += Get-CustomHeader “VMs with C:\ less than $MBFree MB : $($MyCollection.count)” “The following guests have a C:\with less than $MBFree MB Free. If the C:\ disk fills up it may cause issues with the guest Operating System”
$MyReport += Get-HTMLTable $MyCollection
$MyReport += Get-CustomHeaderClose
}
}
It looks like the function that should check free space on VMs actually checks just a hard drive capacity.
I’ve changed this part of code:
from
if (([math]::Round($disk.Capacity/ 1MB)) -lt $MBFree){
to
if (([math]::Round($disk.FreeSpace/ 1MB)) -lt $MBFree){
Now it makes more sense.
[...] a lot of vAdmins I use Alan Renouf‘s vCheck v5 to produce valuable reports but there was an issue, a big [...]
I can’t seem to make the script run as a scheduled task with windows 2008 scheduler.
the task will run but will not seem to stop. The status is alwyys on running mode even after 24 hours.
I have changed my line from:
$VIServer = Connect-VIServer $VISRV
to
$VIServer = Connect-VIServer $VISRV -cred $creds
and the settings for my scheduler are as follows.
Under program/scripts: powershell.exe
Under Add arguments (optional) -noninteractive -noprofile -command “”
Under Start in (optional): C:\Scripts\vCheck
Interesting enough if I run the command from the prompt like this:
J:\>powershell.exe -noninteractive -noprofile -command “”
It would run fine.
SO what it is that I am not doing correctly in windows 2008 scheduler ?
[...] here to download For more information please visit http://www.virtu-al.net/featured-scripts/vcheck/ Filed under: Articles, Scripts, vTools Leave a comment Comments (0) Trackbacks (0) ( [...]
We have multiple vcenter servers in my environment. Could the script be modified to pull data from more than one vcenter server, or would I have to run it individually against each?
The solution to Outlook is actually fairly simple, without going through the “Attachment hack” (+ I prefer my content directly in the e-mail, not in an attachment, makes it easier on mobile devices).
If you just stick all the CSS options into variables, and don’t use classes but only inline-styles, Outlook will parse it without a problem.
So make a variable “$css_dspheader1″ with the exact content of the “dsp” and “dsphead0″, and change the ‘class=”dsp dsphead0″‘ with ‘style=”$($css_variable)”‘, so all the CSS markup is done inline, and not in those CSS styles defined at the top.
While it’s not really pretty, it doesn’t change much from the programming point-of-view, as you’ll only declare your CSS styles once, but they’ll be present multiple times in the mail.
Hi Al
Your Website is absolutely awesome ! I often use your scripts at work or just for new ideas to create my own scripts. Your vCheck is very great, even though I have some running time issues with it. We’ve got a pretty huge environment and so the CapacityInfo part takes almost for ages to complete. So I played around with it a little and figured something out. If I simply add -IntervalSecs 7200 to the cpu.usagemhz.average and mem.consumed.average the hole part is running much faster. If I change the value to 1800 secs it gets even faster. I used measure-command and the time it takes to get the cpu values for only one host is only a third of the time it took before. Maybe this only works for me… but hopefully it helps other people too
I am struggling to get the code to run. Debugging points to the first line (actually second line) in my code:-
param ( [string] $VISRV)
I have added add-pssnapin VMware.VimAutomation.Core as line 1 in my script.
Error is :-
The term ‘param’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At :line:2 char:5
+ param <<<< ( [string] $VISRV)
Using PS v2, PowerCLI 4 u1, on Win2k8 x64.
Hi Rich,
You have to change the first and second lines of your code. The param line should always be the first line. The Add-PSSnapIn line should be after the param line.
Regards, Robert
Ooops…
Thanks Robert
Spoke to soon…
Still getting the error now at line 1 char 5.
Hi I can run the script locally on the vCenter server and manually but I do receive the following warnings in the display:
Warning: There were one or more problems with the server certificate:
* A certification chain processed correctly, but terminated in a root certificate which isn’t trusted by the trust provider.
* The certificate’s CN name does not match the passed value
I also get:
Warning: Unable to populate snapshot size due to insufficient permission.
The account I am using has local admin privileges and also has the administrators role in vCenter itself.
Also when I send the email I get the email but with an error pertaining to Adjusting Connection Information section I have manually specified the credentials as suggested with the same account (local administrator and administrators role in vCenter) but I still get the problem.
Obviously I appreciate it suggests a credentials problem. But can someone clarify what credentials are needed as I thought that would suffice.
Would very much appreciate some advice on this as it would be extremely useful to us if I can get this working.
Thanks Darren
Has anyone got this owrking on Windows 2k8 as a scheduled task? I can get the script to execute with the scheduler, but it fails to connect to the VC. I receive the email advising of the failure to connect-VIserver, so I’m happy SMTP is working at least!
The bit of the script I have looked at is line 702 – 716. I noticed the ‘fix for scheduled tasks’ and the $apppath syntax is for W2K3. Does this need to be modified for W2K8, or does the symbolic link that 2K8 keeps for backwards compatibilty take care of it?
The script runs normally when executed from a batch file, but the scheduler doesn’t seem to pass the connection string properly.
when i run the script it gives only the below message.
“Please specify a VI Server name eg….
powershell.exe vCheck.ps1 vmcpesuwp01lc”
But it doesnt deliver email to my mailbox.
Please can anyone of you let me what i am doing wrong. I am running the sciprts on VC itself. my VC configuration is 2.5 U2 and windows powershell.
I have enter SMTP address in my VC mgmt server configuration.
Thanks
@ Samir
Are you running it from the PowerCLI shell Samir? Did you specify a vCenter Server in the string?
Hi Rich,
Please spare me for not understand the script and how will i get the output.
i m using Windows Power Shell 1.0. I have entered the vCenter Server as below. Do i need to enter the VC server name somewhere else.
Write-Host “Please specify a VI Server name eg….”
Write-Host “powershell.exe vCheck.ps1 vmcpaup01lc”
Note: I am running this script on VC server itself.
No problems Samir.
Firstly, you do not need to modify the script on the lines you mentioned. The ‘write-host’ command just outputs info to the shell, such as error messages. If you have received the message it is because the script does not know which vCenter to connect to.
Secondly, from the PowerCLI shell, CD to the directory where your script is located and use the command:-
./vcheck.ps1 myvcenter
Where myvcenter is the host name of your vCenter server, and assuming the script is called vcheck.ps1. This will launch the script and you should see response output in the shell as it executes.
Hope that makes sense
Sorry, my bad.
Syntax on the command is .\vcheck.ps1 myvcenter
I never could get my slash orientation correct
Hello Rich,
I have changed the script to
Write-Host “Please specify a VI Server name eg….”
Write-Host “powershell.exe vCheck.ps1 MyvCenter”
Then I ran this command on powershell.
.\vCheck5.ps1 vmcpaup01lc
I received an email saying that
The Connect-VISERVER Cmdlet did not work, please check you VI Server.
I think i am really bad in scripting
Hi Samir, try the following
edit your vcheck5.ps1 script, add the following line as line 2 in the script.
add-pssnapin VMware.VimAutomation.Core
save script and then try running .\vcheck5.ps1 vmcpaup01lc
if that still doesn’t work, check you have all the prereqs installed.
◦PowerShell V2 Download from http://support.microsoft.com/kb/968929
◦PowerCLU 4.0 U1 or later version Download from http://www.vmware.com/support/developer/PowerCLI/index.html
Regards
Neil
Hello Neil,
Thanks for the reply.
Now i am getting the below message. Any idea why ?
“There were one or more problems with the server certificate:
* A certification chain processed correctly, but terminated i
der.
* A required certificate is not within its validity period.
* The certificate’s CN name does not match the passed value.
Samir, That’s normal, the reason for that is that the “default” install of your vcentre uses an certificate that does not match your hostname, the script should still work, did it produce an email ok ?
If you really want to get rid of the message you will need to install a certificate, see http://kb.vmware.com/kb/1021514 for details on how to.
Regards
Neil
has anyne got this running on Win 2k8 x64 as a scheduled task? I can get the task to run, but it fails after 5 minutes and forwards an email with the error:-
The Connect-VISERVER Cmdlet did not work, please check you VI Server.
I am passing the command directly into the scheduler as follows:-
Program/Script = C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add Arguments (Optional) = -noexit “& ‘d:\ecoshell_scripts\vcheck\vcheck5.ps1′” my-vcenter
I am using a cred file to pass the authentication, so I am not sure if the error is caused because the VC info has not been passed, or the UID and password.
I have modified the following section of the script to try to make it use the cred file:-
If ($SetUsername -ne “”){
if ((Test-Path -Path $CredFile) -eq $false) {
Set-Cred $CredFile
}
$creds = Get-Cred $SetUsername $CredFile
}
Write-CustomOut “Connecting to VI Server”
$VIServer = Connect-VIServer $VISRV -Credential $creds
If ($VIServer.IsConnected -ne $true){
# Fix for scheduled tasks not running.
$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
}
$VIServer = Connect-VIServer $VISRV -Credential $creds
If ($VIServer.IsConnected -ne $true){
Write $VIServer
send-SMTPmail -to $EmailTo -from $EmailFrom -subject “ERROR: $VISRV vCheck” -smtpserver $SMTPSRV -body “The Connect-VISERVER Cmdlet did not work, please check you VI Server.”
exit
}
I’m not sure what impact the ‘# Fix for Scheduled Tasks Not Running’ has. It seems to be mapped for a Windows 2k3 environment rather than 2k8, but that is probably irrelevant. Maybe my syntax is wrong or incomplete. Anyone have any ideas, or been able to get this to work with task scheduler?
The “The Connect-VISERVER Cmdlet did not work, please check you VI Server.” error message is probably due to your proxy settings.
Use the following cmd to set your powercli to bypass the proxy and try connecting again:
Set-PowerCLIConfiguration -Proxy “NoProxy”
I made an extension to the vCheck script to check for ESX servers that are not compliant with the VMware Update Manager attached baselines. Don’t forget to install the VMware vCenter Update Manager PowerCLI before you try my code. Enjoy!
# Hosts not compliant to VMware Update Manager Baselines
$ShowHostVUMNonCompliance = $true
# —- Hosts VMware Update Manager Baseline non-compliance —-
If ($ShowHostVUMNonCompliance){
Write-CustomOut “..Checking Hosts VMware Update Manager Baseline non-compliance”
Add-PSSnapin -Name VMware.VumAutomation
$NonCompliance = Get-VMHost | Sort-Object -Property Name | Get-Compliance | Where-Object {$_.Status -ne “Compliant”}
If (($NonCompliance | Measure-Object).count -gt 0) {
$MyReport += Get-CustomHeader “Hosts VMware Update Manager Baseline non-compliance : $($NonCompliance.count)” “The following hosts are not compliant to the attached baselines”
$MyReport += Get-HTMLTable ($NonCompliance | Select-Object -Property @{N=”Host”;E={$_.Entity}},@{N=”Baseline”;E={$_.Baseline.Name}},Status)
$MyReport += Get-CustomHeaderClose
}
}
Thanks Robert.
Does PowerCLI try to use the proxy (if configured) even if the exclusion list includes addresses on the same network?
testing now…
I was also wondering… is there a way to force task scheduler to show the posh window as the task executes?
@Robert
Robert I ran the command and set proxy as disable all. I ran the scheduled task but it failed again with the same error. It works ok when run from the shell, so still think the issue is with the task scheduler – just not certain whether the issue is that it hasn’t passed the VI server info or the credentials.
Is there any way of forcing std error output to a log file from the posh script?
regards
For everybody complaining about the speed of the vCheck script try installing the latest PowerCLI version 4.1U1. It made running the vCheck script in my environment much faster.
@Rich B
I wil show you how I run the vCheck script. First, I run the scheduled task with a service account that has sufficient right at the vCenter server. Second, the scheduled task runs a .cmd file with the following line of code:
%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ -command “” > vCheck-vCenterServerName.log 2> vCheck-vCenterServerName-error.log
Replace vCenterServerName with the name of your vCenter server.
All the normal messages of the script will go to the vCheck-vCenterServerName.log file. The error messages will go to the vCheck-vCenterServerName-error.log file.
I see that in my previous post the command line was missing a piece. Probably by inapropriate handling of accolades by the web site software. I will try again. Replace ampersand, accolade-open and accolade-close with the appropriate signs:
%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1″ -command “ampersand accolade-open c:\vCheck.ps1 -vCenterServerName accolade-close” > vCheck–vCenterServerName.log 2> vCheck-vCenterServerName-error.log
@Robert
Thank you again.
Firstly, do I need to pass the -psconsolefile option as I have specified it in the script? Secondly, where in the string you detailed does it pass the vCenter host name?
regards
@Robert
oops… sorry our replies crossed over there!
Thank you
regards
@Robert
Sorry Robert, one last query. Where you pass the vc host name you have prefixed with ” – “. Is that required? My VC has a hyphen as part of the host name – will that cause an issue?
@Rich B
The hyphen in front of the vCenter Server name was a typo. So you should remove the hyphen
.
@ Robert
No problem
I got the script running, many thanks.
I have another question… I am running this script against two separate VC’s. I have 2 separate scheduled tasks configured, pointing at the same script in the same location. When the script runs inititally it creates the mycred.crd file. I assume this will cause an issue if I run the script against 2 VC’s as it can’t create mycred.crd twice in the same location? I also presumed that, if using the same user account to run against the second VC (I have the same account configured with the same permissions on both VC’s), that it would work, unless the encryption algorithm generates some other value, possibly based on the server it is connecting to.
So I created 2 separate copies of vCheck in separate locations. I then ran the script. It seemed to work normally to start with, asking for the authentication initially which I entered. However, after warning about the SSL certs, it then prompted for authentication again. I entered the creds and the script carried on executing normally with no further interaction. After the script had finished, I ran it again, but once more was prompted for creds twice before it would execute.
So I am wondering where the issue lies? I have modified the script so the absolute path to the mycred.crd file is given in both cases, but this makes no difference. Does PoSh cache the mycred.crd value somewhere? I am able to run the script if I pass the VC UID and password in the script, so I am happy the account has the correct permissions. Has anyone seen this before?
Does anyone know how to add a section that will notify you of orphaned VMDKs?
Great script!
I hope you don’t mind but I added a few lines of code to attach the rendered HTML file as an attachment to the e-mail. Outlook 2007 doesn’t support some of the CSS that’s specified in the script.
Changed function Send-SMTP to below:
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body, $Filename) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$att = new-object Net.Mail.Attachment($Filename)
$msg.Attachments.Add($att)
$msg.IsBodyHTML = $true
$mailer.send($msg)
}
Added $Filename to the function Send-SMTPmail line and added:
$att = new-object Net.Mail.Attachment($Filename)
$msg.Attachments.Add($att)
in the middle.
Then I added “$Filename” to line 1574.
There’s most likely a better way to do this, but works for me.
Thank you for producing such a great checking/reporting
script and making it freely available! When I execute the script
(using VMware-PowerCLI-4.1.1-332441), I receive the following
warnings, but the problem I have is the script seems to
hault/freeze on the “.. Checking Snapshots” section. I was only
able to successfully run the script to completion after commenting
out the ‘Snapshot’ section: > .\vCheck5.ps1 {VI_SERVER}
Connecting to VI Server WARNING: Index was outside the bounds of
the array. ..Checking for Map disk region event ..Checking Hosts in
Maintenance Mode WARNING: ‘State’ property is obsolete. Use
‘ConnectionState’ instead. ..Checking Hosts Not responding or
Disconnected ..Checking for VMs swapping or Ballooning WARNING:
‘Host’ property is obsolete. Use ‘VMHost’ instead. I’d very much
like to have the Snapshot information included, are you aware of an
issue with the Snapshot function working in this version of
PowerCLI? I’d very much like to include this information, is there
a fix or work-around that can be applied? Thank you in
advance.
Excellent Script!!!
I have multiple NTP servers set on some ESXi servers and the report says the NTP settings are not correct. I have added both of the IP addresses for the NTP servers in, $ntpserver = “10.1.10.130,10.1.10.131″, but it still says the settings are not correct. I have tried with no comma between IPs and with just a space between IPs. Ideas?
Our email server requires authentication to send an email out, is there a way to put a user name and password for the SMTP server in?
You should be able to separate your ntp server entries with a pipe symbol for this to work.
Since the first of januari the vCheck report shows events in the future in the “ESX/ESXi VMKernel Warnings” section. Of course I like a script that reports about future events
. But I think in this case it is a bug. The PowerCLI Get-Log cmdlet returns messages with a date without the year. E.g. “Dec 12 06:07:32″.
The line in the code:
“{$Details.Time = ([datetime]::ParseExact(($_.split()[0] + ” ” + $_.split()[1] + ” ” + $_.split()[2]), “MMM dd HH:mm:ss”, $SysGlobalization))}”
converts this date into “12-12-2011 6:07:32″. Which has the wrong year.
You can solve this problem by adding the following lines of code at the appropriate places to the vCheck script:
$Today = Get-Date
if ($Details.Time.Month -gt $Today.Month) {$Details.Time=$Details.Time.AddYears(-1)}
My previous solution was an advantage but is not perfect. I still see messages with a future date in januari 2011. So I changed the line starting with if into:
if ($Details.Time.Month -gt $Today.Month -or ($Details.Time.Month -eq $Today.Month -and $Details.Time.Day -gt $Today.Day)) {$Details.Time = $Details.Time.AddYears(-1)}
The only problem still left is that it is possible that you will see error messages from a previous year. I think it is not possible to solve this problem untill the Get-Log cmdlet returns a date with the year included.
Good script. The only thing this is missing is a comparison
of all the hosts in each cluster – along the lines of this
http://www.peetersonline.nl/index.php/vmware/check-vmware-configuration-with-powershell/
I know this should only need to be done when new LUN’s or VLAN’s
are added, but in reality we have had occasions where for one
reason or another it was an issue. Of course those using profiles
don’t have to worry
I agree, that would be a great addition, maybe one day I will get time to update this script with this and the other ideas I have! Perhaps I should make a chargeable version of the script – at least that way it would make it justifiable to the wife when I work weekends
. Great idea though!
Well we all appreciate your efforts even if the wife doesn’t!
If you do add that script it would be worth adding an exclusion for local disks…(in my opinion)
Just as an FYI – I get this warning “WARNING: ‘State’ property is obsolete. Use ‘ConnectionState’ instead.”
Any plans to write an updated script?
Ha! Good timing – I just happened to be looking for another script when I decided to add my comment. I didn’t see Al’s message two above mine!
I will do you a deal, give me 2hrs of your day and I will write it
I noticed for some time now that the script (at least in my
ESXi 4.1 and power CLI 4.1.1 environment) that the lockdown mode
portion shows false positives even though lockdown mode is enabled.
the result even shows all the hosts as LockedMode is “true”.
searched though the comments to see if anyone is experiencing this,
see image for example (i hope html is supported). href='http://img840.imageshack.us/i/lockedz.jpg/'
rel="nofollow"> Uploaded with rel="nofollow">ImageShack.us any ideas?
thanks.
it appears that html is not supported, the link to the
image is ‘http://img840.imageshack.us/img840/1930/lockedz.jpg‘
also, thanks for the tip for multiple NTP servers, worked great for
my environment.
[...] of the best scripts I have ever used is the
Virtu-Al.net vCheck daily report
(http://www.virtu-al.net/featured-scripts/vcheck/). Not only does
it show problems in your virtual infrastructure, it also shows the
power of [...]
Al – Just wanted to say that you’ve got a great script here. If it were possible I would be glad to give you a couple of hours of my day so you could work on this
I’ve spent a couple of hours recently trying to add some features and document other requests. I have a spreadsheet listing some of the requested features (from all the comments on this post) and an updated script with a dozen or so of those features added. I would be glad to share them with you if you are interested.
Thanks again!
Great script. Helps me allot to get a overview over my
VMware Cluster!
That’s great, cant wait to try out your changes and add them to v6, please do send over the spreadsheet and I will add it to the list I have in mind. I love the way people can pick this up and adjust it, that’s one of the things I wanted to be easy when creating the script!
hi, v3 worked perfect in my environment but v5 hangs on
that point: 13:30:06 Connecting to VI Server 13:30:06 Collecting VM
Objects 13:30:08 Collecting VM Host Objects 13:30:10 Collecting
Cluster Objects 13:30:10 Collecting Datastore Objects 13:30:10
Collecting Detailed VM Objects 13:30:13 Collecting Template Objects
13:30:13 Collecting Detailed VI Objects 13:30:14 Collecting
Detailed Alarm Objects 13:30:14 Collecting Detailed VMHost Objects
13:30:19 ..Adding General Summary Info to the report 13:30:26
..Checking Capacity Info any ideas? thanks
Al,
Have you ever thought about open sourcing it, etc? There are licenses that would allow you to keep things from forking, but would allow a larger portion of the community to participate and continue to improve on this already great script.
At a minimum move to a community based approach with hosting on a source forge, github, code plex type repository.
I think you would see some great additions from the community.
I noticed that the VM disk space check would only report on
the 1st disk in the VM. I also would like to report on % free in
addition to MB free. For example, report on all VM disks that have
less than 5% free AND 500MB free. I added the following code to
accomplish the task…. Add this to the details settings section of
the user configurable variables: # VM Disk space left, under x
percent free and under x MB free $diskPercFree = 5 $diskMBFree =
500 Add this to the 2nd user configurable area: # Show VMs disk
space check $ShowGuestDiskFree = $true Add this to the body of the
script. (I added it below the existing section “—- VM Disk Space
- Less than x MB —-” # —- VM Disk Space – Less than x percent
—- If ($ShowGuestDiskFree){ Write-CustomOut “..Checking for
Guests with less than $diskPercFree percent” $MyCollection = @()
$AllVMs = $FullVM | Where {-not $_.Config.Template } | Where {
$_.Runtime.PowerState -eq “poweredOn” -And ($_.Guest.toolsStatus
-ne “toolsNotInstalled” -And $_.Guest.ToolsStatus -ne
“toolsNotRunning”)} $SortedVMs = $AllVMs | Select *,
@{N=”NumDisks”;E={@($_.Guest.Disk.Length)}} | Sort-Object
-Descending NumDisks ForEach ($VMdsk in $SortedVMs){ $myCol = @()
Foreach ($disk in $VMdsk.Guest.Disk){ $CapacityMB =
([math]::Round($disk.Capacity / 1MB)) $FreeSpaceMB =
([math]::Round($disk.FreeSpace / 1MB)) $_ = “” | Select-Object
Name, Path, CapacityMB, FreeSpaceMB, PercFreeSpace $_.Name =
$VMdsk.Name $_.Path = $disk.DiskPath $_.CapacityMB = $CapacityMB
$_.FreeSpaceMB = $FreeSpaceMB $_.PercFreeSpace =
([math]::Round(((100 * ($FreeSpaceMB)) / ($CapacityMB)),0)) $myCol
+= $_ } $MyCollection += $myCol } $VMPercFreeWarn = @($MyCollection
| Where {$_.PercFreeSpace -lt $diskPercFree -and $_.FreeSpaceMB -lt
$diskMBFree} | Sort Name) If (($VMPercFreeWarn |
Measure-Object).count -gt 0) { $MyReport += Get-CustomHeader “VMs
with less than $diskPercFree % free AND $diskMBFree MB free :
$($VMPercFreeWarn.count)” “The following guests have less than
$diskPercFree % Free AND $diskMBFree MB Free, if a guest disk fills
up it may cause issues with the guest Operating System” $MyReport
+= Get-HTMLTable $VMPercFreeWarn $MyReport += Get-CustomHeaderClose
} }
Al, I’ve posted the spreadsheet and modified version of the script on my blog – http://enterpriseadmins.org/blog/?p=238 for your review. I’ve only tested it on one vCenter so other environments may uncover additional issues/problems. Thanks again for creating this script!
Hello Guys,
I have Changed function Send-SMTP to below:
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body, $Filename) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$att = new-object Net.Mail.Attachment($Filename)
$msg.Attachments.Add($att)
$msg.IsBodyHTML = $true
$mailer.send($msg)
}
Added $Filename to the function Send-SMTPmail line and added:
$att = new-object Net.Mail.Attachment($Filename)
$msg.Attachments.Add($att)
But still the reports is not coming as attachment.
Any idea ?
With all these good enhancements going on its probably worth mentioning two issues I’ve seen;
1) With the “The following VMs are located on storage which is only accesible by 1 host,” check, local disks are listed. Should these not be excluded ?
2) The capcity data seems misleading. One cluster shows on the report under CPU that it can have 1500 additional machines based on HA requirements, and yet I know that cluster is reaching significant CPU contention caused mainly by the number of VM’s with 4 vCPU’s.
Also all clusters are reporting as having capacity for hundreds of additional VM’s based on memory, and then all the hosts are listed as having over commited memory. I realise one is based on allocated and the other on used, but the data will surely give people an unrealistic picture of their actual capacity situation ?
I’m being picky of course – its a great report and VMWare would do well to include all this info in the VI client….!
Since other people are submitting requests, I’ll add mine. Most of them are storage centric but I think everyone would benefit from it.
- Top 10 VM consumers of host disk IP (over x number of days).
- Top 10 datastores with highest latency (over x number of days).
- Top 10 datastores with lowest latency and most free space (helps decide where to put the next VM).
- VMs with disk latency higher than x (over x number of days).
The more focus we can put on storage the better performance gets! If you need 48 hours, let me know and I’ll do what I can.
Just a quick question. I am running the script twice a day. but due to the same name of the report generated e.g. VCproductionvCheck_14-1-2011.htm. The previous report gets over written. is it possible to have the output reports name contain timing e.g vmcpesuwp01lcvCheck_14-1-2011_12:08.htm
@Samir – I haven’t tested this, but I believe you could change this line:
$Filename = “C:\tmp\” + $VIServer + “vCheck” + “_” + $Date.Day + “-” + $Date.Month + “-” + $Date.Year + “.htm”
-to-
$Filename = “C:\tmp\” + $VIServer + “vCheck” + “_” + $Date.Day + “-” + $Date.Month + “-” + $Date.Year + “_” + $Date.Hour + “-” + $Date.Minute + “.htm”
To add the hour and minute to the output file. You’ll note I used a dash between hour & minute — if I remember correctly, a colon is not a valid character to use in a file name.
Thanks… It worked…
Hi there,
it´s a great script. But i have a “Feature” Request.
It is possible to change the snapshot check so that i get only the size of the snapshot files? Not the whole used space?
I found a script that do this, but i am not familiar with PowerCli to implement it.
Bye Christian
I’m having problems with the credentials. Can’t schedule this script because it asks for username and password many times. Any solution???
Credentials for vCenter or for the WMI calls it makes to the VMs ?
How to know? Many times. I think it never uses the credentials stored in the encrypted file. It asks int the begining, and three or four times during the execution of the script. If I insert the same credentials (the one used in the bigining) works fine.
Excellent script
I have the same problem getting the output as an attachment as Samir described…..
I have Changed function Send-SMTP to below:
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body, $Filename) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$att = new-object Net.Mail.Attachment($Filename)
$msg.Attachments.Add($att)
$msg.IsBodyHTML = $true
$mailer.send($msg)
}
Added $Filename to the function Send-SMTPmail line and added:
$att = new-object Net.Mail.Attachment($Filename)
$msg.Attachments.Add($att)
But still the report is not coming as attachment.
What else do I need to do?
Hi, First of all, thanks for this script, it’s amazing ! I have no scripting knolwedge and I’ve even managed to implement it successfully. Could I add something for a wish list, or if someone has already added this could you let me know the code… I would also like to have a section which reports on disk alignment. I have seen a number of individual scripts, but I’d like to be able to incorporate, it into this excellent script…many thanks for any help you can give me….
I keep getting a log in request at these points:
..Checking VC Services
..Checking VC Error Event Logs
..Checking VC Warning Event Logs
I don’t know which password it wants. Does anyone know how to get this to go away? The information I get from the script is very useful, but I can’t schedule it to go on its own when it stops for these pop-ups.
Thanks
These are the credentials to access your vCenter to read the event logs – Windows credentials
Where has that guy gone with the spreadsheet of all the proposed updates ? Or has Al included them himself already ?
@Simon, I’m the one with the vCheck feature request spreadsheet. I’ve posted the list on Google Docs here: http://bit.ly/dGrNjh. You can check out my web site to find the changes I’ve added.
[...] this week and so far everything has been running smooth and without issues. I did notice that the vCheck script was reporting some warnings in the vCenter log that I had not seen before the [...]
[...] know, I have created a vCheck feature request list (http://bit.ly/dGrNjh) using comments from the Virtu-Al.net site. I’ve been working through them as time [...]
also having the “multiple prompts for credentials” issue when running this script on a windows 2008 R2 (where vCenter is installed) desktop session with AD account nested in local admin group.
no difference if i run it from power VMware CLI window, called out from a command prompt, or from scheduled task.
I have 2 VC’s and this script takes for every to run. I have 58 Hosts and 783 Guests in one VC and 43 Hosts and 388 Guests in the other VC. Can I automate this script to run overnight? How?
Yes you can, it was designed to be run as a scheduled task, check here for more info on how to do this: http://www.virtu-al.net/2009/07/10/running-a-powercli-scheduled-task/
Oh yeah, im also working on the performance in the next version, trying to make it faster !
What is the format for the credentials file. What to automate the running of this script.
I’ve just implemented the script on a W2K8 R2 server with vSphere 4.1. When I manually kick off the script I see a couple errors in the PowerShell window.
First error is after Host & Maintenance Mode:
Warning ‘State’ property is obsolete, use ‘ConnectionState’ instead.
Second error is after VMs Swapping & Ballooning:
Warning ‘Host’ property is obsolete, use ‘VMHost’ instead.
Tried swappping the recommendation out in a couple of places for the first warning and saving the script, then running but still got the warning… Any ideas?
Thanks
@Mark, I believe the warnings you see relate to changes in PowerCLI 4.1U1. The script will still run with the warning in place and the results of the check are still accurate. However, if you don’t want to see these warnings, you can check out the modifications I’ve made to Al’s awesome vCheck script. The latest changes I’ve made are available here:
http://enterpriseadmins.org/blog/scripting/vcheck-daily-report-version-5-31/
I’ve added a handful of feature requests — found from right here in the comments — plus a few other things I wanted along the way.
I hope this works for you!
How long does it run for? I ran the script and it is stuck at checking “capacity info” for more than 16 hours. It would be nice if there is some kind of logging to find whats going on… Is it normal to be collecting capacity info for 16 hours? I have around 20 ESX and a handful of datastores.
Hi – great script!
Q: v5 reports ballooning for a few VMs – but I go into VI client performance->memory and the ballooning shown there (this is ESXi 4.1U1) is Zero for realtime, day, week.
Can you explain the script reporting ballooning, but VI client reports zero ballooning of memory?
thanks!
Hi
Here is some code to find which machines have change block tracking disabled. there is a problem with the logic. Ill sit down at some point and look again. But current code is below, let me know if it can be improved upon
# Check for Disabled Change Block tracking (not complete, some logic is wrong, and will only report on FALSE at present (ESX4 or above required))
$ShowCBT = $true
$CBTdefault = “True”
# —- Show CBT —– #
if ($ShowCBT) {
Write-CustomOut “..Checking for CBT status”
$cbt = @()
foreach ($vmguest in ($VM | get-view))
{
$name = $vmguest.name
$vmguest.Config.ChangeTrackingEnabled | %{
if (!$vmguest.Config.ChangeTrackingEnabled -eq $CBTdefault){
$myObj = “” |
select Name,ChangeBlockTrackingStatus
$myObj.Name = $name
$myObj.ChangeBlockTrackingStatus = $vmguest.Config.ChangeTrackingEnabled
$cbt += $myObj
}
}
}
If (($cbt | Measure-Object).count -gt 0 -or $ShowAllHeaders) {
if ($CBTdefault -eq ‘true’){
$myReport += Get-CustomHeader “Change Block Tracking Disabled Count : $($cbt.count)”
}
else {
$myReport += Get-CustomHeader “Change Block Tracking Enabled Count : $($cbt.count)”
}
$myReport += Get-HTMLTable $cbt
$MyReport += Get-CustomHeaderClose
}
}
Hope this proves usefull to someone
Thanks
Hi Alan,
Great updates. Can you add some checks for SRM protected VM’s.
@Travveler: You can attach the report but not display it – Use the modifications from @shartma and enable $DisplayToScreen — just comment out the Invoke-item so the report is never actually displayed during runtime:
if ($DisplayToScreen) {
Write-CustomOut “..Displaying HTML results”
if (-not (test-path c:\tmp\)){
MD c:\tmp | Out-Null
}
$Filename = “C:\tmp\” + $VIServer + “vCheck” + “_” + $Date.Day + “-” + $Date.Month + “-” + $Date.Year + “.htm”
$MyReport | out-file -encoding ASCII -filepath $Filename
#Invoke-Item $Filename
Hi
Ok, I have updated my CBT code to actually work, its not the most elegant but does work
# Show CBT Variations
$ShowCBT = $true
$CBTdefault = “true”
# —- Show CBT —– #
if ($ShowCBT) {
Write-CustomOut “..Checking for CBT status”
$cbt = @()
foreach ($vmguest in ($VM | get-view))
{
$name = $vmguest.name
$vmguest.Config.ChangeTrackingEnabled | %{
if ($CBTdefault -eq ‘true’){
if (!$vmguest.Config.ChangeTrackingEnabled -eq ‘true’){
$myObj = “” |
select Name,ChangeBlockTrackingStatus
$myObj.Name = $name
$myObj.ChangeBlockTrackingStatus = $vmguest.Config.ChangeTrackingEnabled
$cbt += $myObj
}
}
else {
if ($vmguest.Config.ChangeTrackingEnabled -eq ‘true’){
$myObj = “” |
select Name,ChangeBlockTrackingStatus
$myObj.Name = $name
$myObj.ChangeBlockTrackingStatus = $vmguest.Config.ChangeTrackingEnabled
$cbt += $myObj
}
}
}
}
If (($cbt | Measure-Object).count -gt 0 -or $ShowAllHeaders) {
if ($CBTdefault -eq ‘true’){
$myReport += Get-CustomHeader “Change Block Tracking Disabled Count : $($cbt.count)”
}
else{
$myReport += Get-CustomHeader “Change Block Tracking Enabled Count : $($cbt.count)”
}
$myReport += Get-HTMLTable $cbt
$MyReport += Get-CustomHeaderClose
}
}
Thanks
Why would you care about CBT anyway ? I would like to know the benefit of the added code.
I’m using a read-only account for safety, one of the VCs I access also gives me the typo’d error message:
5:00:00 PM ..Checking Snapshots
WARNING: Unable to populate snapshot size due to unsiffucient permissions.
‘unsiffucient’?
Doesn’t appear to come from the script.
By the way, I found vcheck from the book I received this week:
VMware vSphere
PowerCLI Reference
c2011
Pages 430, 656-657
Changed Block Tracking (CBT) is the ability of a virtual machine to keep track of disk sectors that have changed. The CBT feature can be accessed by third-party applications as part of the vStorage APIs for Data Protection. Applications can use the API to query the VMkernel to return the blocks of data that have changed on a virtual disk since the last backup operation. Detail is available here: http://kb.vmware.com/kb/1020128.
If you have a backup solution that leverages CBT, you’ll want to make sure these bits are enabled. The code is very good in that it not only checks for CBT, but allows you to configure if the default CBT value should be enabled or disabled. For example, if your backup solution does not use the vStorage APIs for Data Protection you probably do not want the overhead of tracking which blocks change.
Has anyone else had any problems getting it to report VM Disk space available?
# VM Disk space left, set the amount you would like to report on
$MBFree = 10000
Great Script! any idea how to schedule the script to run daily/weekly?
Cheers.
Not getting any emails, even after chainging the code to send as attatchment as per above comments.
This is run on the vcenter server 4.1.0 box
Still runs fine on my old virtual center 2.5 box (with the script execution pointed at the new vc)
Hi,
the script run fine but it take only 5 minutes to finish…
but there’s no dispay in IE, no file in C:\tmp
could someone tell me why ?
I am new to PowerCLI and I love it. This report is very helpful. I am having a small issue when I run it. When the report is completed, it is showing duplicates of everything. (Number of host showing 14 and we only have 7, VMs showing 128 and we only have 64, Snapshots are showing twice) Any ideas why that would be showing up this way?
Awesome Script, got it running a part of our operations team daily checks.
thanks.
When I see stuff like this, I realize how much of a no0b I am
[...] other day I was trying to execute a modified version of Alan Renouf’s vCheckv5 PowerShell script on a vCenter server. usually before running PowerShell scripts locally on a [...]
[...] other day I was trying to execute a modified version of Alan Renouf’s vCheckv5 PowerShell script on a vCenter server. usually before running PowerShell scripts locally on a [...]
Hmm, my report is only showing 1 host, 1 vm, 1 datastore, etc. when I have bunches of each). The script authenticates fine (as I can use the connect-viserver command fine alone). I’m pretty new at PowerCLI (let alone PowerShell). Any hints as to what to look for? Is there a debug mode?
Bah. Answered my own question. Running it from the vcenter server didn’t work. Running it from my local desktop worked fine. Weird, no?
The check for ESXi Lockdown Mode doesn’t work correctly. I changed the line:
$ESXiUnlocked = @($ESXiLockDown | Where { $_.LockedMode -eq “False” })
into:
$ESXiUnlocked = @($ESXiLockDown | Where { -not $_.LockedMode })
to make it work. The problem is that $_.LockedMode is a boolean and not a string.
Well – great script and I am sure many hours are poured into this and provided to the community. To that I say bravo. However I do not see many folks having any of their issues resolved. (perhaps I am mistaken)
Anyhow I got past my issue with the the “Connect-VISERVER Cmdlet did not work, please check you VI Server”. Albeit perhaps not the best way but what I did is remove the variable $VISRV by simply hardcoding my virtual center server name in those 7 locations within the script. If I need to connect to another vcenter then I would change that name. I know not the best but I am no powershell expert when i was trying to debug it I kept getting messages saying that value is empty even though I typed my server name for it to connect.
Now on to the following error:
WARNING: Unable to populate snapshot size due to unsiffucient permissions.
I see other folks asking but no solutions?? Has anyone got passed this????
Pete L
At the beginning of the script it starts “param( [string] $VISRV)”. So you pass the name of your management server to the script as a paramenter. That saves you having to change the script each time you run it against a different management server!!!
What permissions role are you running the script as ? The easy solution is obviously to run it as an admin…
Hello Simon.
I simply used the instructions provided and wondered why it did not work. So i just did what I did but thanks for the tip. However that is no longer concern of mine anymore as I am able to get by via the hard coding I did. I am running this script as a domain admin and I have full admin rights in vcenter.
The next issue I wish to resolve is that pesky error with the snapshots. Insuffecient permissions”
Hello – anyone have a solution for this. I am not certain what else to try..
WARNING: Unable to populate snapshot size due to unsiffucient permissions
thanks for reading.
Brilliant script! Took about 6 hours to run, but the end result was spot on. Is there a way to incorporate within the report a section stating all powered off VMs and their Last Powered On date and time with the results in descending order, “oldest to most recent”?
Any help with regards to this would be greatly appreciated.
@Pete L,
I’ve just tested the script and do not get the ‘insufficient permissions’ error message with a read-only vCenter user. I did find reports of this problem on the VMware Communities forum at http://communities.vmware.com/thread/251568?start=15&tstart=0. One of the suggestions in that thread is to verify the version of PowerCLI:
Please verify that the latest build [of PowerCLI] is installed correctly: run Get-PowerCLIVersion cmdlet and verify the output is “VMware vSphere PowerCLI 4.1 build 264274″
Hi. I already checked all of that but here is the result to post to the masses after running the version cmdlet: (as you can see I meet the version requirements)
[vSphere PowerCLI] C:\> get-powercliversion
PowerCLI Version
—————-
VMware vSphere PowerCLI 4.1 build 264274
[vSphere PowerCLI] C:\>
As for rights. I have all the required rights (admin)
I am not sure what else to try.. H’mmmm :
10:53:17 AM Connecting to VI Server
10:53:17 AM Collecting VM Objects
10:53:24 AM Collecting VM Host Objects
10:53:36 AM Collecting Cluster Objects
10:53:37 AM Collecting Datastore Objects
10:53:37 AM Collecting Detailed VM Objects
10:54:12 AM Collecting Template Objects
10:54:14 AM Collecting Detailed VI Objects
10:54:15 AM Collecting Detailed Alarm Objects
10:54:15 AM Collecting Detailed VMHost Objects
10:55:39 AM ..Adding General Summary Info to the report
10:55:59 AM ..Checking Capacity Info
10:58:25 AM ..Checking Snapshots
WARNING: Unable to populate snapshot size due to unsiffucient permissions.
@Pete L,
Here is another idea…the vCheck script is doing some fairly complex stuff with regard to snapshot size. Looking through the code I do not see any custom error messages related to permissions in the snapshot sections — which makes me believe that the error is produced by a native PowerCLI function. To simplify troubleshooting, can you try running the following command:
get-vm |get-snapshot
I also noticed that a newer version of PowerCLI was available (VMWare vSphere PowerCLI 4.1 U1 build 332441). The release notes do not mention fixes in Get-Snapshot, but it might be worth trying.
@bwuch
running get-vm |get-snapshot worked fine and provided me with output to the screen of the machines with snapshots.
How can I get this to work when it runs it report in the script?
.
So I am now puzzled..
I will be a happy man..
We have a primary Virtualcenter that is connected to 3 other virtualcenters in linked mode. When I run the script against the primary virtual center (and wanting it to just return the contacts of the primary) the script is crawling all of the linked VC’s as well and taking over an hour to finish. Is there a way to have it not crawl the linked VC’s or specify just the Datacenter you want it to inventory?
@Pete L,
The code vCheck uses to collect snapshot data is fairly complex…I’ve tried to re-write and simplify that section. The following script contains only the new snapshot collector code: http://enterpriseadmins.org/blog/wp-content/uploads/2011/05/troubleshootSnapshots.ps1_.txt
Could you try and run this (independently of vCheck) and see if this code works without warning? If so I can help you retrofit the new code into vCheck 5.
Thanks!
Bwuch,
thanks for doing this.. However ran the script and got the following result after a few minutes:
WARNING: Unable to populate snapshot size due to unsiffucient permissions.
Wait a minute!
After I got that error I walked away from the PC when I came back it displayed virtual machine names with snapshot information..!!
Hmm I am going to run again
@bwuch
Ok here is an update from my comments above:
ran your script again. And within 3 minutes I received the message :
WARNING: Unable to populate snapshot size due to unsiffucient permissions.
so I decided to do other things on the pc and see if results would magically appear again delayed sorta speak cause I do have the error message above but no prompt.
Then about 15 minutes the results displayed:
here is a small sample:
VM : MACHINEAP03 – PDF Converter
SnapshotName : Consolidate Helper- 0
DaysOld : 60
Creator :
SizeMB : 59348.03
Created : 3/12/2011 10:11:58 AM
Description : Helper snapshot for online consolidate.
@Pete L — Holy cow! I get bent out of shape if someone asks to keep a snapshot more than 3 days…I’m not even sure what to say about a 60 day old/59GB snapshot!
I do have some good news. I was able to re-create the warning message you see from an old PC I had with PowerCLI 4.0 U1 build 208462. Using the same user account/permissions on a different computer with PowerCLI 4.1 U1 build 332441 worked fine. Would it be possible to upgrade the PowerCLI version to 4.1U1 on your machine?
@bwuch:
I upgraded powercli per your suggestion. Re-ran your code and within 7 minutes it provided me the results. No error messages!!!
Thanks! Now does this code still need to be incorporated into the vcheck?
p.s. as for the aging snapshots,… Yeah tell me about it.. Thus why I want to run this script and have it email the admins!
One admin has snapshots of over 200 days old in his 3.x environment. Now you can see why I want this script to function
Hi,
Great script, but I also would like to use it on some ‘stand-alone ESXi islands’ (without VC).
Any chance it can also work on a single ESXi host?
Regards,
Molski
@bwuch (Brian),
First off I want to say “thank you”. I ran the vcheck script in the the u1 version of PowerCli and about 6 hours later I got a report on our virtual environment.
The only messages I saw in powercli were:
12:58:56 PM ..Checking Hosts in Maintenance Mode
WARNING: ‘State’ property is obsolete. Use ‘ConnectionState’ instead.
12:58:56 PM ..Checking Hosts Not responding or Disconnected
12:58:56 PM ..Checking Hosts Overcommit state
12:59:32 PM ..Checking Hosts Dead Lun Path
WARNING: ‘LunPath’ property is obsolete. Use ‘Name’ instead (it holds the same
value).
1:09:29 PM ..Checking for created or cloned VMs
1:10:09 PM ..Checking for removed VMs
1:10:10 PM ..Checking for VMs with over 2 vCPUs
1:10:10 PM ..Checking for VMs swapping or Ballooning
WARNING: ‘Host’ property is obsolete. Use ‘VMHost’ instead.
I will assume i just change those values and I am good to go?
UPDATE
I took vcheck 5.3 and started running it yesterday (May 12) @ 4:44PM Eastern. Today is the day after and it is still running (I think) :
4:44:08 PM Connecting to VI Server
WARNING: There were one or more problems with the server certificate:
* The X509 chain could not be built up to the root certificate.
* The certificate’s CN name does not match the passed value.
4:44:12 PM Collecting VM Objects
4:44:16 PM Collecting Datacenter Objects
4:44:16 PM Collecting VM Host Objects
4:44:25 PM Collecting Cluster Objects
4:44:25 PM Collecting Datastore Objects
4:44:25 PM Collecting Detailed VM Objects
4:45:00 PM Collecting Template Objects
4:45:01 PM Collecting Detailed VI Objects
4:45:01 PM Collecting Detailed Alarm Objects
4:45:02 PM Collecting Detailed VMHost Objects
4:46:20 PM ..Adding General Summary Info to the report
4:46:33 PM ..Checking Capacity Info
4:48:27 PM ..Checking Capacity Info (disk)
4:48:59 PM ..Checking Cluster CPU ratio
4:49:48 PM ..Checking Snapshots
It has been sitting at Checking Snapshots since 4:49PM yesterday May12. I am posting this the next morning at 7:23AM.
[...] have been working on addressing a comment I noticed on the Virtu-Al vCheck comments (http://www.virtu-al.net/featured-scripts/vcheck/). The issue relates to a warning message returned in the “checking snapshots” [...]
@Pete L, if you try to change the references from ‘host’ to ‘vmhost’ or ‘state’ to ‘connectionstate’ in the code you’ll find that it is used in various places and requires multiple updates (I know because I’ve done it). Once you fix the first one the next time you run the script it will warn you in a different spot (the warnings appear to display only once per console window session). I’ve got a couple more changes I would like to incorporate and then I’ll share the version I have with this already addressed.
Did you ever get past the snapshot check from yesterday? I’ve had blips in my network connection cause the script to appear to hang — and it usually doesn’t recover. I have an environment with about 900 VMs and 45 or so hosts and it only takes 2.5 hours to run the check. If the script is still hung from 5/13 7:23am I’d press CTRL+C to cancel and then try again. I’m not sure how large your environment is, but I’d hope the script doesn’t take 12 hours.
@Kenny, it would be possible to add a section with all powered off VMs and the last time there was a power on event (I don’t see a way to determine the last time it was actually running). The code is already available here: http://blogs.vmware.com/vipowershell/2009/10/when-was-the-last-time-that-vm-was-powered-on.html — it just needs modified slightly so it fits into the vCheck framework.
@Tracy M, I’ve ran vCheck against a vCenter Linked Mode configuration before and it only returned the one specific vCenter results (I was actually wanting to get all of them). If you run the PowerCLI cmdlet Get-PowerCLIConfiguration what is listed under the “Default Server Mode” heading? Two modes are available (single|multiple) — I’m just curious if that could allow you to report on more than one vCenter.
@molski, the vCheck code can run against stand-alone ESXi hosts. However, some of the checks are not going to work (like the ones that look at the vCenter services and event logs). You could leave the checks running — since they return zero results they will not appear in the report. If you want to improve performance you may want to disable some of the inapplicable checks in the header section by chaning their status variable to $false. Here are a few of the ones I’d look for:
# VC Service Details
$ShowVCDetails = $true
# VC Event Log Errors
$ShowVCError = $true
# VC Event Log Warnings
$ShowVCWarn = $true
@Bwuch
Hi first off thanks. I re-ran the vcheck 5.3 and about 6 hours later it emailed me a report. It just seems to take forever on the snapshot thing. Anyhow I finally had to kill that other job that was going for over 24hours and simply restarted it.
Anyhow you mentioned you wanted to make changes? Anyhow I appreciate your time and attention to this as I can appreciate you have a life and a real job as well?
@Pete L, just curious, do you have a lot of snapshots? If I’m reading the vCheck code correctly it may loop through nearly 1000 VI events for each snapshot (looking for the creation time and user name). If you have a lot of snapshots I could see that performing poorly.
I do have a modified version of vCheck…which includes the new snapshot check code from the other day. If you would like to test it you can get a copy here: http://bit.ly/kKvxw1
Oh, and yes, I do have a life and real job
@Bwuch,
I ran the latest script 5.38 and it took about 2hrs and 20 mins to run. That is a huge difference! I am used to over 6.
[...] For anyone working with VMware and PowerShell, Alan’s blog is a “must bookmark” as it contains some great information regarding using PowerCLI, including this great script for reporting your virtual infrastructure state. [...]
Thanks for a great script but I’m after a little bit of help. I’ve managed to amend it slightly as suggested above to send the report as an attachment but now I’m trying to remove it from the body of the email. Any suggestions will be gratefully received.
Thanks
I found a way around my linked mode VCenter issue. And it should also work for those that only want to audit a certain segment (specific Datacenter, ESX Host) of their Environment. I created a local account on the Vcenter server that only has read-only access to the segments I want to be audited. For My environment since this local account only exists on the Primary Vcenter and not the linked ones, the audit cannot walk farther than the primary. Hope this helps someone else.
@Mark T,
In the vCheck5 code around line 1574 you’ll see a line that says:
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV $MyReport
If you do not want the report to appear in the body you can modify/replace the $MyReport variable with your desired message body HTML. An example would be:
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV “vCheck is complete”
@Tracy M,
Great solution on limiting the vCheck scanning scope. I’m still confused how PowerCLI is using the other linked mode instances — I want my vCheck to do that
Based on the $ShowLunPath section, i wrote this to add a check for “Fixed” or “RoundRobin” multipath policy for each lun. If the path for a lun is not “RoundRobin” it will triggers a warning.
If you have decided to use this multipath policy it can be helpful.
Could be add in a future version on this script.
Need to add
# RoundRobin
$ShowRoundRobin = $true
at the start..and
# —- Round-Robin —-
If ($ShowRoundRobin){
Write-CustomOut “..Checking for Round-Robin on each LUN”
$Fixed = @()
foreach ($esxhost in ($VMH | where {$_.State -eq “Connected” -or $_.State -eq “Maintenance”}))
{
$esxluns = Get-ScsiLun -vmhost $esxhost -CanonicalName “naa.6006*”
foreach ($esxlun in $esxluns){
if ($esxlun.multipathpolicy -ne “RoundRobin”) {
$myObj = “” |
Select VMHost, Lunpath, MultipathPolicy
$myObj.VMHost = $esxhost
$myObj.Lunpath = $esxlun.CanonicalName
$myObj.Multipathpolicy = $esxlun.multipathpolicy
$Fixed += $myObj
}
}
}
If (($Fixed | Measure-Object).count -gt 0) {
$MyReport += Get-CustomHeader “FIXED LUN Path : $($Fixed.count)” “Some path are not using Round-Robin policy.”
$MyReport += Get-HTMLTable $Fixed
$MyReport += Get-CustomHeaderClose
}
}
I added limiting the scope to report only on a specific cluster, or hosts and/or VMs within a specific cluster. (I wanted to keep my various testing clusters out of the mix.)
Write-CustomOut “Collecting VM Objects”
If ($VMReportContainer -ne “”)
{ $VM = Get-VM -Location $VMReportContainer | Sort Name }
Else
{ $VM = Get-VM | Sort Name }
Write-CustomOut “Collecting Datacenter Objects”
$Datacenter = get-datacenter | sort name
Write-CustomOut “Collecting VM Host Objects”
If ($HostReportContainer -ne “”)
{ $VMH = Get-VMHost -Location $HostReportContainer | Sort Name }
Else
{ $VMH = Get-VMHost | Sort Name }
Write-CustomOut “Collecting Cluster Objects”
If ($ReportCluster -ne “”)
{ $Clusters = Get-Cluster -Name $ReportCluster | Sort Name }
Else
{ $Clusters = Get-Cluster | Sort Name }
Write-CustomOut “Collecting Datastore Objects”
$Datastores = Get-Datastore | Sort Name
Hope it helps someone with a similar need.
[...] scripts and other stuff that a VMware Automation Admin uses! I showed a fellow student mr Renoufs vCheck Script, and he really liked [...]
I tried the file attachment changes mentioned to send the report as an attachment. Upon completion I would receive an email but no attachment.
Any one else?
Also Dead LUNS when I sent the report to the admin he would simply say ” I dont have any dead luns everything checks out fine…”
does anybody know how the capacity section is calculated? i have run the report and it told me i have 168 (est num vm left cpu) and 87 (est num vm left mem). what exactly is this telling me. i could setup 87 1gb memory vm’s?
@Bwuch
I came across this link (http://blogs.vmware.com/vipowershell/2009/10/when-was-the-last-time-that-vm-was-powered-on.html) while I tried to incorporate this section in vCheck, but when testing the script provided on the blog separately nothing happened. Would this be because the script was written in PowerCLI 4.0? I am currently running 4.1.1.
Has anyone gotten this to work without vCenter? I have 10 ESXi hosts and have no problem enumerating them via a DNS query, but when I go to connect, I either have to use
Connect-ViServer -username -password, or I get prompted. If I try-
$SetUsername = “root”
$CredFile = “c:\data\dev\powershell\root.crd”
$VISRV = Connect-VIServer $server -credential $creds
I don’t get prompted (and it doesn’t work)
Other than that, this is pretty frickin sweet for what I am trying to do, and I have been able to add other tables to give me a full breakdown of my environment.
Any thoughts?
Nevermind. It was the way I jacked with the script to ‘discover my hosts’
Get-WmiObject -Computer MyDomainController -Namespace “root\MicrosoftDNS” -Class “MicrosoftDNS_AType” `
-filter “ContainerName=’prod.mydomain.com’” | Select-Object ownername | where-Object {$_.ownername -like “*irv-dev-esxi*”} | Select Ownername |`
foreach-object{
$VISRV = Connect-VIServer $server -credential $creds
}
I had put this before the functions so the ‘if ($VISRV -eq “”)’ didn’t fail. I guess powershell requires functions to be listed before they are called as opposed to vbscript since its not compiled at runtime?
@Kenny,
The code provided here (http://blogs.vmware.com/vipowershell/2009/10/when-was-the-last-time-that-vm-was-powered-on.html) is a function. For it to return anything, you’ll need to give it a VM object. For example you could run Get-VM | where {$_.PowerState -eq “PoweredOff”} | Get-LastPowerOn
If you add the function into the vCheck and include something like the following code block, you should get a section that shows you what you are interested in:
$guestDownTime = @()
$vm | where {$_.PowerState -eq “PoweredOff”} | %{
$Details = “” | select VM, PowerState, LastPowerOn, DiskGB
$Details.VM = $_.name
$Details.PowerState = $_.PowerState
$Details.LastPowerOn = Get-LastPowerOn $_
$Details.DiskGB = [math]::round($_.UsedSpaceGB, 2)
$guestDownTime += $Details
}
if (($guestDownTime |Measure-Object).count -gt 0){
$MyReport += get-customheader “Powered off VMs : $($guestDownTime.count)” “The following VMs are currently powered off and could possibily be relocated to slower storage or deleted if no longer required. The date/time of the most recent power on task is included for reference.”
$MyReport += get-htmltable ($guestDownTime | sort LastPowerOn)
$MyReport += Get-CustomHeaderClose
}
}
@Pete L,
As a former storage admin, I can confirm that we never have problems with LUNs — the problem is always with the app owner
Anyway, the Dead Luns section shows dead paths between ESX and the LUN. This may not indicate a LUN issue and could show up if you have storage removed from your environment — the ESX host is looking for a LUN that no longer exists and assumes it is dead. In the past I have re-scanned HBA’s and had this error disappear.
@Thomas M,
The capacity section is calculated based off of statistics and HA fail over requirements. The numbers estimate the number of virtual machines you could run, under average load, accounting for your HA failover level. The numbers do not account for peak operation and I doubt you could actually run that number of virtual machines in your cluster — but it is pretty good in terms of a rough estimate.
@Thomas M,
I did something around what you are looking for a little while back.
Have a look here http://www.virtu-al.net/contact-me/ for my entry dated March 16th, 2011 – 12:11 item no 2
Basically it was based on a percentile usage. let me know if that helps, code is a bit rough but should work.
We use it along with the normal capacity planning stats to come up with a more accurate guess
Thanks
@bwuch,
Any chance of incorporating the following code to allow for authenticated relay on smtp
Add
$SmtpUser = “servername”
$SmtpPass = “password”
Modify the Send-SMTPmail function to look like
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$mailer.Credentials = [System.Net.NetworkCredential]::($smtpusername, $smtppassword)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$msg.IsBodyHTML = $true
$mailer.send($msg)
}
Thanks
@bwuch
One word… – Brilliant!
It worked like a bomb, not one glitch. I’m sure the code you gave would help many others that were looking for these type of results.
Again, thank you very much. (***tipping my hat***)
I have come back to using vcheck5.3 after a couple months of not. I am finding now however that the vm’s removed/cloned/created is not reporting. This used to work and all other stats appear to show correct information on the report.
Any ideas?
Al,
What can I say! You are a God amongst Men. I have been using this excellent script since version 2 (I Think?)
However, I feel I must point out an issue I am experiencing with the section reporting Triggered Alarms for VMs and Hosts. I ran your report which reported that there were no VMs with triggered alarms but later found that there were by trawling the VIEvent log. It seems to be that I (and maybe others) am experiencing a bug in PowerCLI (since your logic looks faultless to me).
Your section is:
# —- VM Alarm —-
If ($ShowVMAlarm){
Write-CustomOut “..Checking VM Alarms”
$vmsalarms = @()
foreach ($VMView in $FullVM){
if ($VMView.TriggeredAlarmState){
$VMsTriggeredAlarms = $VMView.TriggeredAlarmState
Foreach ($VMsTriggeredAlarm in $VMsTriggeredAlarms){
$Details = “” | Select-Object Object, Alarm, Status, Time
$Details.Object = $VMView.name
$Details.Alarm = ($valarms |?{$_.value -eq ($VMsTriggeredAlarm.alarm.value)}).name
$Details.Status = $VMsTriggeredAlarm.OverallStatus
$Details.Time = $VMsTriggeredAlarm.time
$vmsalarms += $Details
}
}
}
However:
$VMsTriggeredAlarm.alarm.value does not return any values nor indeed if you reference any property under $VMsTriggeredAlarm directly. Using $VMsTriggeredAlarm | fl * works though and $VMsTriggeredAlarm | gm shows the properties but direct reference does not work ?!?!?!?!?!?
The only way I could get this to work was to perform a select on $VMsTriggeredAlarm to get access to the alarms and then your logic worked. BIZZARRE!!!
The code I got to work is:
# —- VM Alarm —-
If ($ShowVMAlarm){
Write-CustomOut “..Checking VM Alarms”
if(!$alarms){
$alarms = $alarmMgr.GetAlarm($null)
$valarms = $alarms | select value, @{N=”name”;E={(Get-View -Id $_).Info.Name}}
}
$vmsalarms = @()
foreach ($VMView in $FullVM){
if ($VMView.TriggeredAlarmState){
$VMsTriggeredAlarms = $VMView.TriggeredAlarmState
Foreach ($VMsTriggeredAlarm in $VMsTriggeredAlarms){
$Details = “” | Select-Object Object, Alarm, Status, Time
$Details.Object = $VMView.name
$Details.Alarm = ($valarms | where{$_.value -eq (($VMsTriggeredAlarm | select alarm).alarm.value)}).name
$Details.Status = ($VMsTriggeredAlarm | select overallstatus).OverallStatus
$Details.Time = ($VMsTriggeredAlarm | select time).time
$vmsalarms += $Details
}
}
}
Have you seen this before or is this just me ?
I’d appreciate your thoughts as this seems bonkers to me!
Keep up the great work.
#BUMP#
I tried the file attachment changes mentioned to send the report as an attachment. Upon completion I would receive an embedded email report but no attachment.
Any one else?
hints? things to check?
Great script. Is it possible to direct the output to a html file?
run the script in a scheduled task that would essentially do this :
vcheck5.ps1 myvcenter > myventer.html.
This is different than the result just popping up in a new html window. I’d want this to run unattended while logged out. Then another script would ftp the myvcenter.html file up to an internal web site. Do this for all my vcenters and in this central web site, I’d have a dashboard where I could see today’s report for each vcenter. So all I need is for the html output to go to a file.
thanks
Roger
I found it down the bottom of the script.
@Pete L,
This is a two part deal. Between lines 243 and 244 (right after “$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)”) you’ll want to add something like this:
$attachment = new-object Net.Mail.Attachment($Filename)
$msg.attachments.add($attachment)
This makes sure the file is attached to the email when it is sent. You’ll also need to make sure that the file you want to attach is actually created (normally only happens if $DisplayToScreen is set to $true, which you may not want for a scheduled task). You could also verify this happens if around line 1571 (right above the “if ($SendEmail)” line) you add code like this:
$Filename = “C:\tmp\” + $VIServer + “vCheck” + “_” + $Date.Day + “-” + $Date.Month + “-” + $Date.Year + “.htm”
$MyReport | out-file -encoding ASCII -filepath $Filename
This will cause the Out-File command to execute even if the $DisplayToScreen is not enabled. The file will be created anyway — and then it will be available to attach to your message.
Hope this helps!
@Bwuch.
Thanks that did the trick. I was missing this important piece ($Filename)
Hey there, just wondering if there was any plans to make this write to a word doc or PDF form? and maybe adding some charts and stuff in? I know from a management point of view, they like the pretty pictures
If you dont ask, you dont know right?
@matt – Why would you want that ? Its not that type of report really – its for people who support the environment. It would also mean people having to install office etc on whatever servers they use to monitor the environments.
There are all kinds of tools for doing graphical management reports but this is a daily health check…
@simon, this is why I am asking the questions, to find out if this tool is not suitable, what other options may be out there to get “graphical management reports” obviously without the cost associated with them.
And you could go down the openxml document format for office 2007, that way you only require the framework to be installed I am led to believe?
@Matt – you may want to check out veeam reporter, there is a free version of the tool that will suffice. It will also provide you with a visio diagrams of the infrastructure.
@Matt,
You may also want to check out one of the first scripts I wrote (just dont look at the code
here:
http://www.virtu-al.net/2008/08/15/exporting-virtual-infrastructure-information-to-ms-word/
And also if its a visio diagram make sure you check out the VMware PowerPack for PowerGUI which offers this for free and is based on this original script: http://www.virtu-al.net/2009/01/26/vdiagram-draw-your-vi-with-one-script/
@Virtu-Al, I actually stumbled across that script already, and have had a play with it… finally got it to somewhat work, using the 32bit version of the PowerCLI run time, and it was producing graphs….
Wont look at code too much, although I am a newbie to PS, so will look ok to me LOL
You know what management are like, they want all the fluffy management reports, with pretty pictures ohh and of capacity predictions without the costs. So if I can automate something with powercli, powershell and the like then it gives me a nice missions on cutting my teeth with the whole environment.
[...] and looking at the service status, this is useful and something I have been using as part of my vCheck script for a long time but recently became useful for a [...]
Hi, love your work !
Is it possible to only make a report of a particulair datacenter?
because we have multiple datacenters on out farm
@c0de1, I don’t believe the code is setup to limit reporting to a single datacenter. However, I have seen someone mention a clever work around that might help. If you create a user account that only has permissions to a single datacenter, and then run the vCheck using that account it will only include results from the datacenter it has permissions to read. Hope this helps!
[...] when I connect to vCenter. The purpose for this will be to run scheduled tasks, such as running the vCheck daily script. I will probably setup a service account for this, that will be a vCenter sever local admin, so I [...]
Great script and thanks for sharing. however I am stuill unable to receive email. I can run the script and see the results on the broswer but just cant get email. Please Help!
# Set the SMTP Server address
$SMTPSRV = “smtp.hello.com”
# Set the Email address to recieve from
$EmailFrom = “admin@hello.com”
# Set the Email address to send the email t
$EmailTo = “test1@hello.com”
# Use the following item to define if an email report should be sent once completed
$SendEmail = $true
# Use the following item to define if an email report should be sent once completed
$SendEmail = $true
if ($SendEmail) {
Write-CustomOut “..Sending Email”
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV $MyReport.Replace(“class=`”dsp “,”class=`”")
}
@wayvirtural,
I had a problem sending mail from PowerShell at one point, but turned out to be a policy my antivirus guy had pushed down to prevent mass mailing worms. You can try this from a powershell window to see if you have a similar restriction:
Send-MailMessage -SmtpServer “smtp.hello.com” -From “admin@hello.com” -To “test1@hello.com” -Subject “Test message” -BodyAsHtml -Body “This is a test message.”
If you a message like this: “Send-MailMessage : Unable to connect to the remote server” you may have something like that going on too.
Hello, excellent script, very good.
I need a validate a UUID VM conflict (two o more VM with same UUID) … please review this feature report in next version …
thks
@Jorge Cruz,
It doesn’t appear that I have any duplicate UUID’s in my environment, but I think the following code would show you all of the duplicates:
$vmview = Get-View -ViewType VirtualMachine | Select @{Label=”VM Name”;Expression={$_.Config.Name}},@{Label=”VM UUID”;Expression={$_.Config.Uuid}}
$vmview | Group-Object -Property “VM UUID” | Where-Object {$_.Count -gt 1} | %{ $myObj += $_.Group }
$myObj | Sort “VM UUID”, “VM Name”
Please let me know if it works out!
Thanks,
@bwuch
Like clock work, I run this script regularly especially after adding the “LastPowerOn” section. Now however I am attempting to add a section naming the VMs and their current network adapter types. I am using this cmdlet “Get-VM | Sort Name | Get-NetworkAdapter”, but it does not display the VM name. Are there other cmdlets to produce these results?
hey guys,
i’m trying to run this script as a scheduled task with a service user instead of my personal admin. scheduling works great acutally, but for some reason when i run the script with the service user, it keeps asking me for credentials at the following points:
- “..Checking VC Services”
- “..Checking VC Error Event Logs”
- “..Checking VC Warning Event Logs”
Even when i manually type in the credentials of the service user when promted, it seems that the service user is not able to capture those information. The service user has local admin rights on the vCenter server and administrator rights within vCenter (propagated).
What am i missing? thanks for your help!
@Kenny, you can get the VM name also with:
Get-VM | Get-NetworkAdapter | Select-Object -Property @{N=”VM”;E={$_.Parent}},
Name,Type,NetworkName,MacAddress,WakeOnLanEnabled
@Robert,
Cmdlet works great, but when I added it to my report none of the object names are displayed under their specified headings. It shows “Object.System[]“. Any further help adding this in the report will be greatly appreciated.
Thanks.
Couple of things I’ve noticed/modified (some already mentioned):
– Missing reporting variables
# Show overallocated datastores
$ShowOverAllocation = $true
# Show VCB snapshots left over
$ShowVCBgarbage = $true
– The email as attachment changes mentioned by someone above = perfect
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body, $attachment) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$msg.IsBodyHTML = $true
$attachment = new-object Net.Mail.Attachment($attachment)
$msg.attachments.add($attachment)
$mailer.send($msg)
}
…
# make sure DisplayToScreen is set to $true also
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV “vCheck report for $VISRV is attached” $Filename
– Added checking for out-of-date tools in the $ShowTools section
$NoTools = @($FullVM | Where {$_.Runtime.Powerstate -eq “poweredOn” -And ($_.Guest.toolsStatus -eq “toolsNotInstalled” -Or $_.Guest.ToolsStatus -eq “toolsNotRunning” -Or $_.Guest.ToolsStatus -eq “toolsOld”)} | Select Name, @{N=”Status”;E={$_.Guest.ToolsStatus}})
– changed the VM disk space section to work on a percentage, not static size. One key thing (for this change and current code checking disk size in MB) is to re-sort the list after building before adding to report, as there is a bug with out-gridview and Get-HTMLTable when the first PSObject has less properties than later ones. Example of the code I use for percentage checking and the resorting is:
# —- VM Disk Space – Less than x % —-
If ($ShowGuestDisk){
Write-CustomOut “..Checking for Guests with less than $PercFreeLimit %”
$MyCollection = @()
$AllVMs = $FullVM | Where {-not $_.Config.Template } | Where { $_.Runtime.PowerState -eq “poweredOn” -And ($_.Guest.toolsStatus -ne “toolsNotInstalled” -And $_.Guest.ToolsStatus -ne “toolsNotRunning”)}
$SortedVMs = $AllVMs | Select *, @{N=”NumDisks”;E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
ForEach ($VMdsk in $SortedVMs){
$Details = New-object PSObject
$DiskNum = 0
Foreach ($disk in $VMdsk.Guest.Disk){
if ($disk.Capacity -ne 0){
$PercFree = ([math]::Round((($disk.FreeSpace / 1MB)/($disk.Capacity/ 1MB))*100))
} else {
$PercFree = 0
}
if ($PercFree -le $PercFreeLimit){
$Details | Add-Member -Name Name -Value $VMdsk.name -Membertype NoteProperty
$Details | Add-Member -Name “Disk$($DiskNum)path” -MemberType NoteProperty -Value $Disk.DiskPath
$Details | Add-Member -Name “Disk$($DiskNum)Capacity(MB)” -MemberType NoteProperty -Value ([math]::Round($disk.Capacity/ 1MB))
$Details | Add-Member -Name “Disk$($DiskNum)FreeSpace(MB)” -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1MB))
$Details | Add-Member -Name “Disk$($DiskNum)%Free” -MemberType NoteProperty -Value $PercFree
$DiskNum++
}
}
if (($Details | get-member -membertype properties) -ne $null) {
$Details | Add-Member -Name “ViolatingDiskCount” -MemberType NoteProperty -Value $DiskNum
$MyCollection += $Details
}
}
If (($MyCollection | Measure-Object).count -gt 0) {
$MySortedCollection = $MyCollection | Sort-Object -Descending ViolatingDiskCount | Select * -exclude ViolatingDiskCount
$MyReport += Get-CustomHeader “VMs with less than $PercFreeLimit % Free Space : $($MyCollection.count)” “The following guests have less than $PercFree % Free, if a guest disk fills up it may cause issues with the guest Operating System”
$MyReport += Get-HTMLTable $MySortedCollection
$MyReport += Get-CustomHeaderClose
}
}
Script is excellent though, can’t wait for 5.1
Finally got this to run as a scheduled task, using local user account on Win2008R2. I also had the problem where it only reports 1 host.
Changed the Connect-VIServer line to:
$VIServer = Connect-VIServer $VISRV -cred $creds
Changed the $SetUsername line to:
$SetUsername = “Computer\localuser”
Changed $CredFile line to:
$CredFile = “C:\vCheck_Reports\vc_cred.txt”
Pre-created the directory listed for CredFile, but do NOT create the file.
Run the script as the user referenced as $SetUsername, it will prompt you, enter the name and password. Should be good to run as a task.
Note that I cheated on a couple of things.
first, I commented
param( [string] $VISRV)
and configured the vcenter in the config section
$VISRV = “vCenter.domain.loc”
second, I added this line right after the “Start of script” line:
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Now my Task command is: powershell.exe
and for arguments:
-File “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\vCheck5.ps1″
Hopefully that saves somebody some time!
can u add vmkuptime.pl report in the vchek
Hi,
is it possible in a very simple way to let the output not go the screen or email but to a file on a specific location?
love your script !
@c0de1,
Comment the following lines by prefixing them with a # sign
Line 1562 = #if ($DisplayToScreen) {
Line 1569 = #Invoke-Item $Filename
Line 1570 = #}
This will cause the script to export the file but not Invoke (open) the report.
@bwuch
Nice, thanks, but how can i say where the file must go ?
@bwuch
Nevermind i found it
Hi
I realy like your script, but sending mail doesn’t work for me, i need autehntication
i have the following
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(“xxxxxx@xxx.xxx”, “xxxxxxxx”);
$msg.IsBodyHTML = $true
$mailer.send($msg)
}
# Set the SMTP Server address
$SMTPSRV = “xxxx.xxx.xxx”
# Set the Email address to recieve from
$EmailFrom = “xxxxxx@xxx.xxx”
# Set the Email address to send the email to
$EmailTo = “xxxxxx@xxx.xxx”
I don’t have any experience with scripting, so i guess i do something wrong
btw sendmail is true
Regards
Jaap
Well, it took me a little while to get this to actually run, but its golden. Running this on my VC right now and hoping for some good detailed info. Still dont see graphs though…. : /
@jaap,
Could you try running the following code from a powershell window to see if you get the email message? You’ll need to change the SMTP password, server, to/from addresses and the mydomain\username:
$smtpPassword = “MySmtpPassw0rd” | ConvertTo-SecureString -asPlainText -Force
Send-MailMessage -SmtpServer “smtp.mydomain.local” -From “test@mydomain.local” -To “me@mydomain.local” -Body “This is a test” -Subject “TEST” -Credential (New-Object System.Management.Automation.PSCredential(“mydomain\username”,$smtpPassword))
If it works I can walk you through using the Send-MailMessage cmdlet in your existing vCheck script.
NOT SHOWING VM’s ADDED and REMOVED?
Hey Guys,
The feature to show vm’s added and removed used to work. When I reinstalled my workstation and re-downloaded the script I am finding the other report functionality works correctly but it will not report on vm’s added or removed in X days. I have it set to 10. I’m not sure if this is somehow related to our VC setup or something in the script I am doing incorrectly.
Any ideas?
I’ve created a Get-CustomField function to output certain VMs with a specific value in a custom field:
function Get-CustomField {
param($item)
foreach ($cf in $item.CustomFields) {
if ($cf.Value) {
$field = “” | Select Key, Value, EntityName
$field.key = $cf.Key
$field.Value = $cf.Value
$field.EntityName = $item.Name
Write-Output $field
}
}
}
Get-VM | Foreach { Get-CustomField $_ } | where {$_.value -eq “test”} | Out-GridView
Now I would like to shutdown or start up these VMs with these values by using “Stop-VM” and “Start-VM” but it returns “The input object cannot be bound…” error. Is this possible using this function?
Seems the download isn’t working. I would love to try the script out though
Excuse me, I got a found not found error. Is the script still available?
Not able to get the Linux VM’s server information
Keep getting File Not Found when trying to download.
Still working on restoring my site after a hack.
good luck with your restore, alan and thanks for the script!
i hope this version is not too old?
http://web.archive.org/web/20101110085412/http://virtu-al.net/Downloads/vCheck/vCheck5.ps1
The download should now be re-available again – sorry for the delay,
[...] Setup information and example report all at: vCheck (Daily Report) http://www.virtu-al.net/featured-scripts/vcheck/ [...]
Looks like I was using the wrong function. Using the following basic cmdlet worked perfectly fine when trying to shutdown a VM with a specific value in a custom field:
Get-VM | where {$_.CustomFields["ShutdownDaily"] -eq “Yes”} | Shutdown-VMGuest -Confirm:$false
Hope this helps anyone else wanting to do this.
Do you have any SQL script which can tell how many time VM was powered on in last 30/60/120 days?
No, I dont write SQL scripts.
Where can I get PowerCLU? I am running PowerCLI 5.0 and just get a ton of errors when I try the script as I cant find a download of PowerCLU for PowerCLI 5?
It is PowerCLI 5.0 you need, what are the errors you are getting ?
Hi Alan, thanks for the script, it works great.
I found it inconvenient that mem.swapped only gives you a high water mark – the same value every day. Since I can’t reboot servers every time they swap to reset the swapped value I changed the script in the VMs Swapping or Ballooning section to:
(Get-Stat -Entity $_ -Stat mem.swapoutRate.average -Start (get-date).AddDays(-1) -Finish (get-date) -ErrorAction SilentlyContinue | measure-object value -max).Maximum
This shows me if a VM has actually swapped during the last 24h.
Just wanted to share that.
Regards
Tranquilo
hi, use your script for reporting and i love it !
I only miss some things:
- patch levels (which patches installed) from esx server
- CPU usage per esx server
- MEM usage per esx server
Is this simple to modify in your script ?
User column for Snapshots and VMs created, cloned and removed are blank on my reports. A bit of digging and I can see that the VIEvent.username property is set to “User” and not the actual username that created the VM, e.t.c.
This was working. Not sure what has changed, I thought it might have been an upgrade from PowerCLI 4.1 to PowerCLI 4.1.1 but I have just uninstalled 4.1.1 and reinstalled 4.1 but still can not get the username from the VIEvent object.
Please could some explain what “VM with mismatch power custom fields/powerstate” is supposed to mean.
All my VM’s are listed in this section.
Hi,
I tried this script and ran into some truoble. I updated the smtp IP and the username/credentials. But when I run the script its just exists without showing any output.. The only output i receive is as given below (I am running the script from the VCenter Server itself – that is why I use the loopback IP – I tried with using the FQDN and the IP as well but same results):
PS C:\Users\admin\Desktop\PowerCLI Scripts> .\vCheck5.ps1 127.0.0.1
5:01:50 AM Connecting to VI Server
PS C:\Users\admin\Desktop\PowerCLI Scripts>
Can someone help me to find out whats wrong?
getting Access Denied when the script is checking the following
VC Error Event logs
VC Warning event logs
VC Services
I’m even getting this Access Denied message with an account with full domain privilege
Hi All,
Running Version 5.0
Issue with Get-CustomHeader
In Outlook its not displaying the Title or comments in the report. Any idea on what needs to change to correct this?
And as it stands, the whole format and font layout is completely off in Outlook. I understand that this is most likely an M$ related issue in how Outlook’s HTML interpriter is defined, but I’m hoping that someone has tackeled this.
Thanks,
Chris
@ChrisSB
I think I have a workaround that can fix the issue you are seeing in Outlook. If you find the line that looks like this:
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV $MyReport
And change it a bit to look like this:
send-SMTPmail $EmailTo $EmailFrom “$VISRV vCheck Report” $SMTPSRV $MyReport.Replace(“class=`”dsp “,”class=`””)
One of the style sheet headings will be removed in the email before it goes out. Outlook doesn’t properly render nested style sheets which causes this problem. The emailed output doesn’t look as good as the HTML file that is created, but it is much better than what you are seeing now.
Hope it helps!
@bwuch
Hey
Can’t make the script run!
error:
File C:\temp\vCheck5.ps1 cannot be loaded. The file C:\temp\vCheck5.ps1 is not
digitally signed.
It’s running
[...] vSphere test / report script Just found that by accident : Virtu-Al | Virtually everything is poshable Reply With Quote + Reply to Thread « Previous Thread | Next [...]
Hi
In line 1120 rember to change “Version 7″ to “Version 8″ if you are using vSphere 5.0.
I’m trying to run the script from my workstation to a vcenter server which is located on another non-trusted domain and I always get asked to provide user/pass (and then I can’t automate it with a scheduled task).
I’ve provided the other domain’s credentials inside the script, but that didn’t help.
Is there a way to achieve this?
BTW – Great script, love it!
Hey Dan D (August 23, 2011)
super schedule setup, Thanks
The NTP-check always lists every host – but NTP-server is always correct and service running.
Has anybody encountered that problem?
Thx
tranquilo
Great Script, makes the daily checks thorough and consistent. Another nice feature could be to show a summary of VM Guest disk types: thin, thick. For our environment we thick everything on the VM side (SAN Array side it varies), so sometimes VM admins will create a thin disk not knowing. So this would essentially catch those configuration inconsistencies.
Hi, have a question about the script.
Does the VMs Created or Cloned (Last x Day(s) only show per month ?
Cause i need a report of the previous month
so on the last day of the month i collect with the script, but there is now info about created, removed vm’s in the list
i have set it to the last 30 days to look for.
And there where creations and deletion of vm’s in that month.
Awesome script, already tweaked it a bit for our environment.
One of the things im working on, though my posh’s isnt as clean as yours.
-checking ESXi hosts for central logging enabled, and if not then displaying whatt local datastore is keeping the logs.(working on it)
-Printing report directly to sharepoint (done)
-find “NUMA” violators/problem VMs (not started)
-how many smotions happen over a time period (not started)
-Identify Luns using Fixed PSP (not started)
Is there a way to display the machine name and OS version by what datastore it belongs to? That would be nice addition to the report (at least I think it would be )
I think this would be helpful for folks that have a san that is cable to do perform deduplication on the datastores. If all virtual guests with same os version would belong in the same datastore this would greatly be a benefit for a deduplication thus getting storage space back. So syaing that if it was possible to list that then the admin can sprinkly the machines around to in the datastores accordingly.
just a thought.. Perhaps a oneline command of sorts?
great script.
Would love to see a check on objects that have alarm actions disabled.
Has anyone been able to exclude VMs from sections such as VMtools, CPU Ready?
In VC we have a test cluster that suffers from lack resources and VMtools issues we’d rather not report on in vCheck.
[...] browsing the vCheck 5 report (Thank you Alan), I noticed the following error: Active Directory Web Services encountered an error while reading [...]
Is is possible to list how many VMs per host? It has ben suggested to us to have a limit of 30 VMs per host in our environment as a best practice. The script is great!
[...] vCheck: http://www.virtu-al.net/featured-scripts/vcheck/ [...]
Puh it takes about +12 hours to complete – is that normal?
20:50:15 Collecting VM Objects
20:50:18 Collecting VM Host Objects
20:50:21 Collecting Cluster Objects
20:50:21 Collecting Datastore Objects
20:50:22 Collecting Detailed VM Objects
20:50:32 Collecting Template Objects
20:50:33 Collecting Detailed VI Objects
20:50:33 Collecting Detailed Alarm Objects
20:50:34 Collecting Detailed VMHost Objects
20:50:42 ..Adding General Summary Info to the report
20:50:49 ..Checking Capacity Info
21:16:28 ..Checking Snapshots
08:37:33 ..Checking Datastores
08:37:33 ..Checking for Map disk region event
08:37:33 ..Checking Hosts in Maintenance Mode
WARNING: ‘State’ property is obsolete. Use ‘ConnectionState’ instead.
08:37:34 ..Checking Hosts Not responding or Disconnected
08:37:34 ..Checking Hosts Overcommit state
08:37:46 ..Checking Hosts Dead Lun Path
WARNING: ‘LunPath’ property is obsolete. Use ‘Name’ instead (it holds the same
value).
08:39:02 ..Checking for created or cloned VMs
08:39:28 ..Checking for removed VMs
08:39:30 ..Checking for VMs with over 2 vCPUs
08:39:30 ..Checking for VMs swapping or Ballooning
WARNING: ‘Host’ property is obsolete. Use ‘VMHost’ instead.
08:43:30 ..Checking invalid or inaccessible VM
08:43:30 ..Checking HA VM reset
08:43:38 ..Checking HA VM restart
08:43:45 ..Checking Host Swapfile datastores
08:43:45 ..Checking DRS Migrations
08:43:52 ..Checking Cluster Slot Sizes
08:43:54 ..Checking for Guests with less than 10 MB
08:43:55 ..Checking for ESXi with Technical Support mode enabled
08:44:21 ..Checking for ESXi hosts which do not have Lockdown mode enabled
08:44:32 ..Checking VM Hardware Version
08:44:32 ..Checking VI Events
08:44:39 ..Checking VMs in Inconsistent folders
08:44:39 ..Checking VM Tools
08:44:39 ..Checking VM Tools Issues
08:48:58 ..Checking for connected CDRoms
08:50:04 ..Checking for connected floppy drives
08:51:11 ..Checking Datastores assigned to single hosts for VMs
08:51:14 ..Checking NTP Name and Service
08:51:20 ..Checking VM CPU %RDY
08:55:09 ..Checking VM CPU Usage
09:19:45 ..Checking Number of VMs per Datastore
09:19:50 ..Checking Host Configuration Issues
09:19:50 ..Checking Host Alarms
09:20:05 ..Checking VM Alarms
09:20:05 ..Checking Cluster Configuration Issues
09:20:05 ..Checking VC Services
09:20:06 ..Checking VC Error Event Logs
09:20:18 ..Checking VC Warning Event Logs
09:20:26 ..Checking VMKernel Warnings
09:20:43 ..Displaying HTML results
09:20:44 ..Sending Email
PowerCLI C:\it\vmware>
Thanks for the timings, this is useful when looking at areas to optimize for future versions.
>> It has ben suggested to us to have a limit
>> of 30 VMs per host in our environment as a
>> best practice.
Let me guess – a hardware manufacturer made that suggestion? # of guest VMs is one of the last things I would measure. You are virtualizing your guest OS’s to better utilize your hardware (among other things) why would someone claim X number of VMs should be the best practice without examinging load and resources used. 30 of one type of guest on one type of host would be way too many … 30 of another type of guest on another type of host would be way too few. Can’t just throw out a number. Someone wants to sell more hardware.
Upon executing I get warnings for depreciated properties, no deal breakers but items I figured it couldn’t hurt to bring to your attention for future releases.
WARNING: ‘State’ property is obsolete. Use ‘ConnectionState’ instead
It looks like it’s coming from the $MaintHosts =@ line (I currently have it open in notepad so I can’t get you a real line count at the moment.)
Also
WARNING: ‘Host’ property is obsolete. Use ‘VMHost’ Instead
which appears to be coming from the $BALSWAP line
Not a deal breaker, just something to look into
[...] vCheck (Report of your VI Environment) [...]
Thanks, I know about the warnings, need to fix that in a future version.
Does this work fine on ESXi 5 vcenter.
As I could do with this?
Cheers
Luke
Luke,
Yep should do, works fine on mine. Let me know if you hit any issues.
Hi Al,
I want to be able to see what VM’s have updated tools, I have tried a few bits of code but want to add it to this script. Can you help?
This is fantastic art of work! Just wanted to add something I noticed, if there are lot of ESX hosts in the cluster the “LUN check” part of this report is not clearly visible. The LUN naa.ID’s overwrites the coloumns and it becomes messy. Is there any way to put a slider to move it to right. thanks.
hi Virtu-Al ,
is it possible that we can export report generated by vcheck 5 into excel, if yes kindly guide how it can be done.
Hi Al – love your script. I’ve made a few modifications to your script to fit my environment, but this makes updating to new versions difficult.
Would it be possible to add a section for identifying VMs that are not @ a particular memory reservation level?
As a VSPP, I get charged for memory reservation which must be a minimum of 50% of Allocated RAM. The addition of VMs configured with zero reservation or @ more than 50% of allocated would eliminate my need for a separate script.
Thanks for the great tool!
@Alan (and @slaclair)–
I have a version of the script with all of the depreciated properties fixed if you’d like me to send it. I did a find and replace on all the occurrences of Host and State until the script ran without throwing up any warnings – there were quite a few. I then grabbed a fresh copy from the site and merged in those changes.
Figured it might save you some time.
Hi – I am finding vCheckv5 is incorrectly flagging HW v8 as old in the “VMs with old Hardware” section.
Easy enough to fix to support vSPhere new HW v8 –
thanks as always
I have to produce monthly uptime report of all esxi hosts. can we get the same with this script.
Hi – I’m using vCheckv5 and have noticed that while under the General Details section there are 7 clusters reported (and a Get-Cluster from PowerCLI also shows 7 clusters) the vCheckv5 report only shows Capacity Planner Info for 4 clusters.
Anyone else seen this issue?
This is really some script.. great effort put into it.. and that shows.. awesome work guys… !!!
cant wait for more
just wanted to know, will this script work while providing multiple vCenter IPs…??
.\vCheck5.ps1 vCenter01 vCenter02 vCenter03
Hi Alan
very nice script – thanks a lot for sharing
I got one question …
I configured the script so that it only monitors the really serious issues.
What can I do so that it does not send an email when none of the tables is populated and instead just silently exits ?
For some reason it is only showing linux guest with < 100mb of space left. It is not showing windows guest with , 100mb of space when I do indeed have a few. Is there something I am doing wrong with it perhaps?
hello,
the capacity planner for CPU on one datacenter is misreporting a negative number of available VMs since we restarted all nodes in the datacenter. Can anyone point me at what might be causing this / where in the script this is defined?
ta
martin.
if i wanted to send the report to multiple emial addresses without crating a whole distribution group for it. can i simply do this?
$EmailTo = “IT@yyyy.com; lpalacio@yyyy.com”
Thank you
No, use “email1@me.com”, “email2@me.com”, “email3@me.com”
Great script. have an issue where the output report has doubled everything. We have 9 hosts in one environment and the report finds 18 hosts? Any ideas??
Thanks
Hi guys, i am new all to script, I have heard every one speak highly of this one, I have downloaded, but it is not working!! Please help, if any one got one with all these nice update I would much appreciate it
So the Creator portion of the Snapshots section is coming up blank since using this on vCenter 5 and PowerCLI 5. Is anybody else experiencing this and if so, is there are fix?
All charts are blank. Other info seems to be there. Any idea why charts are blank? I am using Office 2010.
Thanks,
Morrisos
I have 2 ntp servers:
10.10.10.80
and
10.10.10.85
How should i define the $ntpserver ?
Fred use “10.10.10.80|10.10.10.85″
Thanks Alan ! $ntpserver = “10.10.10.80|10.10.10.85″ working fine!
At hardware version check section i had several VM´s listed although the report shows they are already on hardware version 8
I changed Where {$_.HardwareVersion -ne “Version 7″} to Where {$_.HardwareVersion -ne “Version 8″}
at vSwitch Ports Check section my report is showing all my dvSwitches and at column “ports left” there are no values.
Fred, Yes the dvSwitches dont have that property, I have changed this check in v6 to only look at standard groups, maybe another check will do the work for dvSwitches.