Up until ESX 3.5 Update 4 we had the HealthCheck script schedule to run everyday, but since we updated it does not seem to be able to run.
I have tried it manually and recieved this error:
vSphere PowerCLI C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts> dir
Directory: Microsoft.PowerShell.Core\FileSystem::C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts
Mode LastWriteTime Length Name
-
-
-a- 7/7/2009 2:12 PM 16674 Healthcheck.ps1 - 4/23/2009 6:56 AM 7771 Initialize-VIToolkitEnvironment.ps1
-a
vSphere PowerCLI C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts> ./Healthcheck.ps1
Incomplete string token.
At C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts\Healthcheck.ps1:121 char:270
+ $vmhosts | Sort Name -Descending | % { $server = $_ |get-view; $server.Config.Product | select { $server.Name }, Version, Build, FullName }| Co
nvertTo-Html â?"body "<H2>$cluster Cluster Information.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css' / <<<< >" | Out-File -Ap
pend $filelocation
vSphere PowerCLI C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts>
Any assistance would be greatly appreciated
=================================
Please don't use any and every text editor when editing powershell scripts. In your posted code, you have weird characthers that are causing the issue. I had it as well.
Example: â? (powershell will always error out)
Jason
I have this same problem. Any ideas?
post contents of the ps1 files .. thanks
###########################################################################################
Title: VMware health check
Filename: healtcheck.sp1
Originally Written by Ivo Beerens ivo@ivobeerens.nl
#
Edited by Ade Orimalade
###########################################################################################
Description: Scripts that checks the status of a VMware
enviroment on the following point:
- VMware ESX server Hardware and version
- VMware VC version
- Active Snapshots
- CDROMs connected to VMs
- Floppy drives connected to VMs
- Datastores and the free space available
- VM information such as VMware tools version,
processor and memory limits
- Witch VMs have VMware timesync options not
enabled
###########################################################################################
Configuration:
#
Edit the powershell.ps1 file and edit the following variables:
$vcserver="localhost"
Enter the VC server, if you execute the script on the VC server you can use localhost
$filelocation="D:\temp\healthcheck.htm"
Specify the path where to store the HTML output
$enablemail="yes"
Enable (yes) or disable (no) to sent the script by e-mail
$smtpServer = "mail.ictivity.nl"
Specify the SMTP server in your network
$mailfrom = "VMware Healtcheck <powershell@ivobeerens.nl>"
Specify the from field
$mailto = "ivo.beerens@ictivity.nl"
Specify the e-mail address
###########################################################################################
Usage:
#
Manually run the healthcheck.ps1 script":
1. Open Powershell
2. Browse to the directory where the healthcheck.ps1 script resides
3. enter the command:
./healthcheck.ps1
#
To create a schedule task in for example Windows 2003 use the following
syntax in the run property:
powershell -command "& 'path\healthcheck.ps1'
edit the path
###########################################################################################
####################################
VMware VirtualCenter server name #
####################################
$vcserver="vmvc02.domain.com"
$portvc="443"
##################
Add VI-toolkit #
##################
#Add-PSsnapin VMware.VimAutomation.Core
#Initialize-VIToolkitEnvironment.ps1
connect-VIServer $vcserver
#############
Variables #
#############
$filelocation="c:\VMpillar.htm"
$vcversion = get-view serviceinstance
$snap = get-vm | get-snapshot
$date=get-date
#############################
Add Text to the HTML file #
#############################
ConvertTo-Html –title "Pillar VMware report " –body "
" -head "" | Out-File $filelocation
ConvertTo-Html –title "Pillar VMware report " –body "
",$date -head "" | Out-File -Append $filelocation
ConvertTo-Html –title "Pillar VMware report " –body "
" -head "" | Out-File -Append $filelocation
#
#####################
VMware VC version #
######################
$vcversion.content.about | select Version, Build, FullName | ConvertTo-Html –title "VMware VirtualCenter version" –body "
" -head "" |Out-File -Append $filelocation
#######################
VMware ESX hardware #
#######################
Get-VMHost | Get-View | ForEach-Object { $_.Summary.Hardware } | Select-object Vendor, Model, MemorySize, CpuModel, CpuMhz, NumCpuPkgs, NumCpuCores, NumCpuThreads, NumNics, NumHBAs | ConvertTo-Html –title "VMware ESX server Hardware configuration" –body "
" -head "" | Out-File -Append $filelocation
#######################
VMware ESX versions #
#######################
$clusters = Get-Cluster | Sort Name
ForEach ($cluster in $clusters)
{
$vmhosts = Get-VMHost -Location $cluster
ForEach ($VMhostView in ($vmhosts | Get-View))
{
$TotalHostMemory += $vmhostView.Hardware.MemorySize
}
$vmhosts | Sort Name -Descending | % { $server = $_ |get-view; $server.Config.Product | select { $server.Name }, Version, Build, FullName }| ConvertTo-Html –body "
" -head "" | Out-File -Append $filelocation
$NumHosts = ($vmhosts | Measure-Object).Count
$vms = Get-VM -Location $cluster | Where {$_.PowerState -eq "PoweredOn"}
$NumVMs = $vms.Length
$TotalRAM_GB = ::Round($TotalHostMemory/1GB,$digits)
$TotalVMMemoryMB = $vms | Measure-Object -Property MemoryMB -Sum
$AssignedRAM_GB = ::Round($TotalVMMemoryMB.Sum/1024,$digits)
$PercentageUsed = ::Round((($TotalVMMemoryMB.Sum/1024)/($TotalHostMemory/1GB))*100)
ConvertTo-Html –body " $NumHosts host(s) running $NumVMs virtual machines" -head "" | Out-File -Append $filelocation
ConvertTo-Html –body "Total memory resource = $TotalRAM_GB GB" | Out-File -Append $filelocation
ConvertTo-Html –body "Total Amount of assigned memory = $AssignedRAM_GB GB" | Out-File -Append $filelocation
ConvertTo-Html –body "Memory resource percenatge allocated = $PercentageUsed %" | Out-File -Append $filelocation
Clear-Variable vmhosts -ErrorAction SilentlyContinue
Clear-Variable vms -ErrorAction SilentlyContinue
Clear-Variable NumVMs -ErrorAction SilentlyContinue
Clear-Variable TotalHostMemory -ErrorAction SilentlyContinue
Clear-Variable TotalVMMemoryMB -ErrorAction SilentlyContinue
}
#############
Snapshots #
#############
$snap | select vm, name,created,description | ConvertTo-Html –title "Snaphots active" –body "
" -head ""| Out-File -Append $filelocation
#################################
VMware CDROM connected to VMs #
#################################
Get-vm | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" } } | Select Name | ConvertTo-Html –title "CDROMs connected" –body "
" -head ""|Out-File -Append $filelocation
#########################################
VMware floppy drives connected to VMs #
#########################################
Get-vm | where { $_ | get-floppydrive | where { $_.ConnectionState.Connected -eq "true" } } | select Name |ConvertTo-Html –title "Floppy drives connected" –body "
" -head "" |Out-File -Append $filelocation
######################################################
#VM Information
########################################################
function VM-statavg ($vmImpl, $StatStart, $StatFinish, $statId) {
$stats = $vmImpl | get-stat -stat $statId -intervalmin 120 -maxsamples 360 `
-Start $StatStart -Finish $StatFinish
$statAvg = "{0,9:#.00}" -f ($stats | Measure-Object value -average).average
$statAvg
}
Report for previous day
$DaysBack = 1 # Number of days to go back
$DaysPeriod = 1 # Number of days in the interval
$DayStart = (Get-Date).Date.adddays(- $DaysBack)
$DayFinish = (Get-Date).Date.adddays(- $DaysBack + $DaysPeriod).addminutes(-1)
Report for previous week
$DaysBack = 7 # Number of days to go back
$DaysPeriod = 7 # Number of days in the interval
$WeekStart = (Get-Date).Date.adddays(- $DaysBack)
$WeekFinish = (Get-Date).Date.adddays(- $DaysBack + $DaysPeriod).addminutes(-1)
$report = @()
get-vm | Sort Name -Descending | % {
$vm = Get-View $_.ID
$vms = "" | Select-Object VMName, Hostname, DayAvgCpuUsage, WeekAvgCpuUsage, VMState, TotalCPU, TotalMemory, DayAvgMemUsage, WeekAvgMemUsage, TotalNics, ToolsStatus, ToolsVersion
$vms.VMName = $vm.Name
$vms.HostName = $vm.guest.hostname
$vms.DayAvgCpuUsage = VM-statavg $_ $DayStart $DayFinish "cpu.usage.average"
$vms.WeekAvgCpuUsage = VM-statavg $_ $WeekStart $WeekFinish "cpu.usage.average"
$vms.VMState = $vm.summary.runtime.powerState
$vms.TotalCPU = $vm.summary.config.numcpu
$vms.TotalMemory = $vm.summary.config.memorysizemb
$vms.DayAvgMemUsage = VM-statavg $_ $DayStart $DayFinish "mem.usage.average"
$vms.WeekAvgMemUsage = VM-statavg $_ $WeekStart $WeekFinish "mem.usage.average"
$vms.TotalNics = $vm.summary.config.numEthernetCards
$vms.ToolsStatus = $vm.guest.toolsstatus
$vms.ToolsVersion = $vm.config.tools.toolsversion
$Report += $vms
}
$Report | ConvertTo-Html –title "Virtual Machine information" `
–body "
" `
-head "" | `
Out-File -Append $filelocation
###############################
VMware Timesync not enabled #
###############################
Get-VM | Get-View | ? { $_.Config.Tools.syncTimeWithHost -eq $false } | Select Name | Sort-object Name | ConvertTo-Html –title "VMware timesync not enabled" –body "
" -head "" | Out-File -Append $filelocation
########################################################
Get all datastores and put them in alphabetical order#
########################################################
function Get-DSDevice($dsImpl)
{
$ds = Get-View -Id $dsImpl.Id
$esx = Get-View $ds.Host[0].Key
$hss = Get-View $esx.ConfigManager.StorageSystem
foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){
if($mount.volume.name -eq $ds.Info.Name){
switch($mount.Volume.Type){
"VMFS" {
foreach($ext in $mount.Volume.Extent){
if($mount.volume.name -eq $ds.Info.Name){
$device =$ext.DiskName
}
}
}
"NFS" {
$device = $mount.Volume.RemoteHost + ":" + $mount.Volume.RemotePath
}
}
}
}
$device
}
$datastores = get-vmhost | Get-Datastore | Sort-Object Name
$myColCurrent = @()
foreach ($store in $datastores){
$myObj = "" | Select-Object Name, CapacityGB, UsedGB, PercFree, Type, ID, Accessible
$myObj.Name = $store.Name
$myObj.CapacityGB = "{0:n2}" -f ($store.capacityMB/1kb)
$myObj.UsedGB = "" -f (($store.CapacityMB - $store.FreeSpaceMB)/1kb)
$myObj.PercFree = "" -f (100 * $store.FreeSpaceMB/$store.CapacityMB)
$myObj.Type = $store.Type
$temp = Get-View -Id $store.Id
$myObj.ID = Get-DSDevice $store
$myObj.Accessible = $store.Accessible
$myColCurrent += $myObj
}
Export the output
$myColCurrent | ConvertTo-Html –title "Datastore Information" –body "
" -head "" | Out-File -Append $filelocation
######################################
##RDM Information
#######################################
$report1 = @()
$vms = Get-VM |Sort Name -Descending | Get-View
foreach($vm in $vms){
foreach($dev in $vm.Config.Hardware.Device){
if(($dev.gettype()).Name -eq "VirtualDisk"){
if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or
($dev.Backing.CompatibilityMode -eq "virtualMode")){
$row = "" | select VMName, HDDeviceName, HDFileName, HDMode, HDSize
$row.VMName = $vm.Name
$row.HDDeviceName = $dev.Backing.DeviceName
$row.HDFileName = $dev.Backing.FileName
$row.HDMode = $dev.Backing.CompatibilityMode
$row.HDSize = ::Round((($dev.CapacityInKB)/1048576),2)
$report1 += $row
}
}
}
}
$report1 | ConvertTo-Html –title "Virtual Machine information" –body "
" -head "" | Out-File -Append $filelocation
##############################################
#Datastores with less than 10% free.
################################################
(get-datastore | sort-object @{expression={$_.name};ascending=$true} | `
Where-Object {(($_.freespacemb / $_.capacitymb) * 100) -lt 10} | select name, `
@{name='Available(GB)';expression={"{0,13:#.00}" -f ($_.freespacemb/1gb)}}, `
@{name='Capacity(GB)';expression={"{0,12:#.00}" -f ($_.capacitymb/1gb)}}, `
@{name='% Used';expression={"{0,6:#.00}" -f `
((($_.capacitymb - $_.freespacemb)/$_.capacitymb) * 100)}}`
)| ConvertTo-Html –title "Hot List Datastore" –body "
" -head "" | Out-File -Append $filelocation
######################################################
#VM's that average over 75% memory usage.
########################################################
(get-vm | sort-object @{expression={$_.name};ascending=$true} | `
Where-Object {($_ | get-stat -mem -intervalmin 120 -maxsamples 360 | `
Measure-Object value -ave).average -gt 75} | select name, memorymb, `
@{name='VM Mem Usage';expression={"{0,9:#.00}" -f (($_ | `
get-stat -mem -intervalmin 120 -maxsamples 360 | `
Measure-Object value -ave).average)}} `
)| ConvertTo-Html –title "Hot List VMs" –body "
" -head "" | Out-File -Append $filelocation
######################################################
#Hosts that average over 75% memory usage.
########################################################
(get-vmhost | sort-object @{expression={$_.name};ascending=$true} | `
Where-Object {($_ | `
get-stat -stat mem.usage.average -intervalmin 120 -maxsamples 360 | `
Measure-Object value -ave).average -gt 75} | select name, `
@{name='Host Mem Average %';expression={"{0,18:#.00}" -f ($_ | `
get-stat -stat mem.usage.average -intervalmin 120 -maxsamples 360 | `
measure-object value -ave).average}} `
)| ConvertTo-Html –title "Hot List Hosts" –body "
" -head "" | Out-File -Append $filelocation
##############################
Disconnect session from VC #
##############################
disconnect-viserver -confirm:$false
##########################
End Of VMpillar.ps1 #
Sorry for the delay:
Please don't use any and every text editor when editing powershell scripts. In your posted code, you have weird characthers that are causing the issue. I had it as well.
Example: â? (powershell will always error out)
I use wordpad, notepad or notepad2 when editing. I used PSPad before which caused the problems like this.
Jason
