param( [string] $VISRV) ############################### # vCheck - Daily Error Report # ############################### # Thanks to all who have commented on my blog to help improve this project # Especially - Thanks to Raphaël SCHITZ (http://www.hypervisor.fr/) for his contributions and time # And also thanks to the many vExperts who have added suggestions for this report. # $Version = "5.47" # # Changes: # Version 5.47- bwuch: Added memory per cluster check provided by Ed # Version 5.46- bwuch: Added vRAM check using @LucD function # Version 5.45- bwuch: Updated export options # Version 5.44- bwuch: cleaned up comments and logging # Version 5.43- bwuch: resolved bug with "Host Build versions in use" counter # Version 5.42- bwuch: Added Cluster BIOS Check # Version 5.41- bwuch: Resolved PowerCLI 4.1 warning on line 1327 re: LunPath # Version 5.40- bwuch: Host version greater than/equal 4.1.0 and AD Auth not configured # Version 5.39- bwuch: bug fixes from 5.38 version # Version 5.38- bwuch: bug fix with 'connectionstate' warning # Version 5.37- bwuch: added SYMC to VCB check for Symantec Backup Exec 2010 # Version 5.36- bwuch: changed snapshot function # Version 5.35- bwuch: Added section with Powered Off VMs showing the last powered on date/event. # Version 5.34- bwuch: Added the CBT tracking code provided by rhys on vCheck comments # Version 5.33- bwuch: Modified Cluster config check to vCheck output format http://www.peetersonline.nl/index.php/vmware/check-vmware-configuration-with-powershell/ # Version 5.32- bwuch: Hack to make report look better in Outlook. # Version 5.31- bwuch: Bug fix for LockdownMode # Version 5.30- bwuch: Add check for VMtools installer connected # Version 5.29- bwuch: Add check for VM capacity forecasting # Version 5.28- bwuch: Change to Get-HTMLTable function for possible performance improvements # Version 5.27- bwuch: Added host uptime check # Version 5.26- bwuch: Added host OS pivot table # Version 5.25- bwuch: Added SSL host and vCenter checks # Version 5.24- bwuch: Change to output file name format # Version 5.23- bwuch: Performance fix for mis-named VM check # Version 5.22- bwuch: More changes to prevent 4.1.1 warnings # Version 5.21- bwuch: Change code to prevent warnings when running with PowerCLI 4.1.1 # Version 5.20- bwuch: Add PowerCLI Version check and vCenter Update Manager host baseline compliance # Version 5.19- bwuch: QA/QC bug check fix data issues # Version 5.18- bwuch: Added Guest OS pivot table # Version 5.16- bwuch: Added host hardware check # Version 5.15- bwuch: changed variable name on cluster cpu allocation ratio check # Version 5.14- bwuch: fixed quotes on VM limit check # Version 5.13- bwuch: added sort to old VM hardware check # Version 5.12- bwuch: QA/QC bug check; minor cosmetic fixes # Version 5.11- bwuch: Added check for cluster CPU allocation ratio (ie vCPU to pCore) # Version 5.10- bwuch: Added option to include all headers -- even on tests that return no results # Version 5.09- bwuch: Added several additional checks listed on my blog http://enterpriseadmins.org/blog/?p=196 # Version 5.08- bwuch: Added fix from Leo to check for Free Space instead of capacity # Version 5.07- bwuch: Added check for VMTools that need updated; provided by kevin, slight update by Traveller # Version 5.06- bwuch: Added comment on how to specify multiple NTP servers as suggested by Mark # Version 5.05- bwuch: Added check for unwanted hardware as suggested by Jon # Version 5.04- bwuch: Added fix for select-object statement provided by Ccalvin # Version 5.03- bwuch: Add VM resource limit check using code provided by Ed. # Version 5.02- bwuch: Show VCB garbage bug fix from rvdnieuwendijk # Version 5.01- bwuch: Show overallocation bug fix from James Davis # Version 5.0 - Changed the order and a few titles etc, tidy up ! # Version 4.9 - Added Inacessable VMs # Version 4.8 - Added HA VM restarts and resets # Version 4.7 - VMTools Issues # Version 4.6 - Added VCB Garbage # Version 4.5 - Added Host config issues # Version 4.4 - Added Disk Overcommit check # Version 4.3 - Added vSwitch free ports check # Version 4.2 - Added General Capacity Information based on CPU and MEM ussage per cluster # Version 4.1 - Added the ability to change the colours of the report. # Version 4.0 - HTML Tidy up, comments added for each item and the ability to enable/disable comments. # Version 3.9 - Adjusted log checking to include ESXi Logs # Version 3.8 - Added ESXi check for unsupported mode enabled # Version 3.7 - Added ESXi check for Lockdown Mode Enabled # Version 3.6 - Added VM Memory Swap and Ballooning # Version 3.5 - Added Host Overcommit check # Version 3.4 - Added Guest Disk check for space (MB) # Version 3.3 - Added Size of snapshots # Version 3.2 - Fixed Slot size information issue # Version 3.1 - Added VMs with High CPU Usage # Version 3.0 - Added VMs in mis-matched Folder names # Version 2.9 - Added counts to each titlebar and output to screen whilst running for interactive mode # Version 2.8 - Changed VC Services to show only unexpected status # Version 2.7 - Added VMs with outdated Hardware - vSphere Only # Version 2.6 - Added Slot size check - vSphere Only # version 2.5 - Added report on Hosts in a HA cluster where the swapfile location is set, check the hosts # Version 2.4 - Added VM/Host/Cluster Alerts # Version 2.3 - Added VMs with over x amount of vCPUs # Version 2.2 - Added Dead SCSILuns # Version 2.1 - Now checks for VMs stored on storage available to only one host rather than local storage # Version 2.0 - CPU Ready # Version 1.17 - vmkernel host log file check for warnings # Version 1.16 - NTP Server and service check # Version 1.15 - DRSMigrations & Local Stored VMs # Version 1.14 - Active/Inactive VMs # Version 1.13 - Bug Fixes # Version 1.12 - Added Hosts in Maintenance Mode and not responding + Bug Fixes # Version 1.11 - Simplified mail function. # Version 1.10 - Added How many days old the snapshots are # Version 1.9 - Added ability to change user account which makes the WMI calls # Version 1.8 - Added Real name resolution via AD and sorted disk space by PerfFree # Version 1.7 - Added Event Logs for VMware warnings and errors for past day # Version 1.6 - Add details to service state to see if it is expected or not # Version 1.5 - Check for objects to see if they exist before sending the email + add VMs with No VMTools # You can change the following defaults by altering the below settings: # # Global variables for report output $SMTPSRV = "mysmtpserver.mydomain.local" #SMTP server name $EmailFrom = "me@mydomain.local" #report from address $EmailTo = "me@mydomain.local" #report to address; separate with commas ex: "user1@mydomain.local,user2@mydomain.local" $exportDirectory = "C:\TMP" $dateFormat = "yyyyMMdd_HHmm" # use "d-M-yyyy" for legacy v5.0 format function exportReports { #The following couple of lines verify that variables are in required formats Write-CustomOut "..Processing report export" if (-not (Test-Path $exportDirectory)) { md $exportDirectory | Out-Null } if ($EmailTo.Contains(",")) { $msgTo = $EmailTo.replace(" ","").split(",") } else { $msgTo = $EmailTo } #The following lines cause the report to export to a file. The name changes based on the date/time the vCheck is executed. This is required if you plan to open the file or attach it to an email. It is not required if you send the report in the body of the message. $Filename = $exportDirectory+"\"+$VISrv+"vCheck"+"_"+$date.ToString($dateFormat)+".htm" $MyReport | out-file -encoding ASCII -filepath $Filename #The following line causes the report to appear on screen (you must export to file in the above section too) Invoke-Item $Filename #uncomment the following line to send an email with the report included in the body #Send-MailMessage -Subject "$VISRV vCheck Report" -SmtpServer $SMTPSRV -From $EmailFrom -To $msgTo -BodyAsHtml -Body $MyReport.Replace("class=`"dsp ","class=`"") #uncomment the following line to send an email with the report included as an attachment #Send-MailMessage -Attachments ($Filename) -Subject "$VISRV vCheck Report" -SmtpServer $SMTPSRV -From $EmailFrom -To $msgTo -BodyAsHtml -Body "Thank you for using vCheck $Version on $VISrv" #$MyReport.Replace("class=`"dsp ","class=`"") #uncomment the following three lines to send an email with the report included in the body to an SMTP server that requires authentication #$smtpUsername = "mydomain\username" #$smtpPassword = "MySmtpPassw0rd" | ConvertTo-SecureString -asPlainText -Force #Send-MailMessage -Credential (New-Object System.Management.Automation.PSCredential($smtpUsername,$smtpPassword)) -Subject "$VISRV vCheck Report" -SmtpServer $SMTPSRV -From $EmailFrom -To $msgTo -BodyAsHtml -Body $MyReport.Replace("class=`"dsp ","class=`"") } # Use the following area to define the colours of the report $Colour1 = "CC0000" # Main Title - currently red $Colour2 = "7BA7C7" # Secondary Title - currently blue #### Detail Settings #### # Set the username of the account with permissions to access the VI Server # for event logs and service details - you will be asked for the same username and password # only the first time this runs after setting the below username. # If it is left blank it will use the credentials of the user who runs the script $SetUsername = "" # Set the location to store the credentials in a secure manner $CredFile = ".\mycred.crd" # Set if you would like to see the helpfull comments about areas of the checks $Comments = $true # Set the warning threshold for Datastore % Free Space $DatastoreSpace = "5" # Set the warning threshold for snapshots in days old $SnapshotAge = 14 # Set the number of days to show VMs created & removed for $VMsNewRemovedAge = 5 # Set the number of days of VC Events to check for errors $VCEventAge = 1 # Set the number of days of VC Event Logs to check for warnings and errors $VCEvntlgAge = 1 # Set the number of days of DRS Migrations to report and count on $DRSMigrateAge = 1 # Local Stored VMs, do not report on any VMs who are defined below $LVMDoNotInclude = "Template_*|VDI*" # VMs with CD/Floppy drives not to report on $CDFloppyConnectedOK = "APP*" # The NTP server to check $ntpserver = "pool.ntp.org" #Multiple servers can be specified with pipe separator as in "pool.ntp.org|myntp.domain.local" # vmkernel log file checks - set the number of days to check before today $vmkernelchk = 1 # CPU ready on VMs - To learn more read here: http://communities.vmware.com/docs/DOC-7390 $PercCPUReady = 10.0 # Change the next line to the maximum amount of vCPUs your VMs are allowed $vCpu = 2 # Number of slots available in a cluster $numslots = 10 # VM Cpu above x for the last x days $CPUValue = 75 $CPUDays = 2 # VM Disk space left, set the amount you would like to report on $MBFree = 10 # Max number of VMs per Datastore $NumVMsPerDatastore = 5 # HA VM reset day(s) number $HAVMresetold = 1 # HA VM restart day(s) number $HAVMrestartold = 1 # VMHost/VMFS quota $VMHostVMFSQuota = 28 # Datastore OverAllocation % $OverAllocation = 100 # vSwitch Port Left $vSwitchLeft = 5 # This section can be used to turn off certain areas of the report which may not be relevent to your installation # Set them to $False if you do not want them in your output. # Show headers for all selected tests (not just problem/issues) $ShowAllHeaders = $true # General Summary Info $ShowGenSum = $true # Show version information of PowerCLI and snapins $showPowerCLIVersion = $true # Show CPU Cluster Ratios $ShowCPUClusterRatio = $true # Show Memory Cluster Ratios $ShowMemClusterRatio = $true # Show vRAM Calculations $ShowvRAM = $true # Show Cluster configuration issues $checkClusterDataStores = $true #good for VM datastored $checkClusterLUNs = $true #good for LUNs used by RDM $checkClusterPortGroups = $true #mis-matched port groups within a cluster $checkClusterBIOSVersions = $true #inconsistent BIOS versions in cluster # Snapshot Information $ShowSnap = $true # Datastore Information $Showdata = $true # Show SSL Certificate status $showSSLexpiration = $true # Hosts in Maintenance mode $ShowMaint = $true # Hosts not responding or Disconnected $ShowResDis = $true #Show Host Hardware Issues $ShowHostHdwrIssues = $true #Show hosts without AD Auth enabled $ShowHostADAuth = $true # Dead LunPath $ShowLunPath = $true #Create Guest OS Pivot table $GuestOSPivot = $true # VMs Created or cloned $ShowCreated = $true # VMs vCPU $Showvcpu = $true # VMs Removed $ShowRemoved = $true # Powered Off VMs with last powered on task date $showOffLastPoweredOn = $true # Host Swapfile datastores $ShowSwapFile = $true # DRS Migrations $ShowDRSMig = $true # Cluster Slot Sizes $ShowSlot = $true # VM Hardware Version $ShowHWVer = $true # VI Events $ShowVIevents = $true # VMs in inconsistent folders $ShowFolders = $true # VM Tools $Showtools = $true # Connected CDRoms $ShowCDRom = $true # ConnectedFloppy Drives $ShowFloppy = $true #Find unwanted virtual hardware $showUnwantedHardware = $true $unwantedHardware = "VirtualUSBController|VirtualParallelPort|VirtualSerialPort" # NTP Issues $ShowNTP = $true # Single storage VMs $ShowSingle = $true # VM CPU Ready $ShowCPURDY = $true # Host Alarms $ShowHostAlarm = $true # VM Alarms $ShowVMAlarm = $true # Cluster Alarms $ShowCLUAlarm = $true # Show Datastore Over Allocation $ShowOverAllocation = $true # Show Host Uptime warnings $CheckHostUptime = $true # Show Host vCenter Update Manager Non Compliance $ShowHostVUMNonCompliance = $true # Show Host version pivot table (ESX vs ESXi/with build numbers) $HostOSPivot = $true # VCB garbage $ShowVCBGarbage = $true # Show CBT Variations $ShowCBT = $true $CBTdefault = "true" # VC Service Details $ShowVCDetails = $true # VC Event Log Errors $ShowVCError = $true # VC Event Log Warnings $ShowVCWarn = $true # VMKernel Warning entries $ShowVMKernel = $true # Show VM CPU Usage $ShowVMCPU = $true # Show virtual machines with resource limits $VMresourcelimts = $true #Show thick provisioned virtual disks $ShowThickDisk = $true #Show VMs whose names don't match the installed OS name $ShowMisnamedVM = $true #Show VMs whose configured OS doesn't match installed OS $ShowWrongOS = $true #Show VMs pointing at the wrong syslog server $ShowWrongSyslog = $true $syslogserver = "Your_syslog_server:514" #Show ESXi hosts listening on port 21 (remote TSM enabled) $ShowRemoteTSM = $true # Show ESXi Tech Support mode $ShowTech = $true # Show ESXi Hosts which do not have lockdown mode enabled $Lockdown = $true # Show VMs disk space check $ShowGuestDisk = $true # Show Number of VMs per Datastore $ShowNumVMperDS = $true # Show Overcommit $ShowOvercommit = $true # Show Ballooning and Swapping for VMs $ShowSwapBal = $true # HA VM reset log $HAVMreset = $true # HA VM restart log $HAVMrestart = $true # Host ConfigIssue $ShowHostCIAlarm = $true # Map Disk Region Events (http://kb.vmware.com/kb/1007331) $ShowMapDiskRegionEvents = $true # Capacity Info $ShowCapacityInfo = $true $LimitDiskCapacityForecastToSharedStorageOnly = $true # VMHost/VMFS Quota $VMHostVMFS = $true # Check inaccessible or invalid VM $ShowBlindedVM = $true # Check VMTools Issues $ShowtoolsIssues = $true # Show VMTools that need updates $Showtoolsupdate = $true # Show VMTools installer connected $ShowtoolsConnected = $true # Check vSwitch Port Left $vSwitchCheck = $true ####################################### # Start of script # Turn off Errors $ErrorActionPreference = "silentlycontinue" if ($VISRV -eq ""){ Write-Host Write-Host "Please specify a VI Server name eg...." Write-Host " powershell.exe vCheck.ps1 MyvCenter" Write-Host Write-Host exit } function Write-CustomOut ($Details){ $LogDate = Get-Date -Format T Write-Host "$($LogDate) $Details" } 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) $msg.IsBodyHTML = $true $mailer.send($msg) } Function Get-CustomHTML ($Header){ $Report = @"
$Heading | $($Detail) |
---|