Issue getting healthcheck to run manually or scheduled

Issue getting healthcheck to run manually or scheduled

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
          -a
          - 4/23/2009 6:56 AM 7771 Initialize-VIToolkitEnvironment.ps1
          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

Comments

I have this same problem. Any ideas?

http://www.ttgapers.com

post contents of the ps1 files .. thanks

###########################################################################################

  1. Title: VMware health check

  2. Filename: healtcheck.sp1

  3. Originally Written by Ivo Beerens ivo@ivobeerens.nl

#

  1. Edited by Ade Orimalade

###########################################################################################

  1. Description: Scripts that checks the status of a VMware

  2. enviroment on the following point:

  3. - VMware ESX server Hardware and version

  4. - VMware VC version

  5. - Active Snapshots

  6. - CDROMs connected to VMs

  7. - Floppy drives connected to VMs

  8. - Datastores and the free space available

  9. - VM information such as VMware tools version,

  10. processor and memory limits

  11. - Witch VMs have VMware timesync options not

  12. enabled

###########################################################################################

  1. Configuration:

#

  1. Edit the powershell.ps1 file and edit the following variables:

  2. $vcserver="localhost"

  3. Enter the VC server, if you execute the script on the VC server you can use localhost

  4. $filelocation="D:\temp\healthcheck.htm"

  5. Specify the path where to store the HTML output

  6. $enablemail="yes"

  7. Enable (yes) or disable (no) to sent the script by e-mail

  8. $smtpServer = "mail.ictivity.nl"

  9. Specify the SMTP server in your network

  10. $mailfrom = "VMware Healtcheck <powershell@ivobeerens.nl>"

  11. Specify the from field

  12. $mailto = "ivo.beerens@ictivity.nl"

  13. Specify the e-mail address

###########################################################################################

  1. Usage:

#

  1. Manually run the healthcheck.ps1 script":

  2. 1. Open Powershell

  3. 2. Browse to the directory where the healthcheck.ps1 script resides

  4. 3. enter the command:

  5. ./healthcheck.ps1

#

  1. To create a schedule task in for example Windows 2003 use the following

  2. syntax in the run property:

  3. powershell -command "& 'path\healthcheck.ps1'

  4. edit the path

###########################################################################################

####################################

  1. VMware VirtualCenter server name #

####################################

$vcserver="vmvc02.domain.com"

$portvc="443"

##################

  1. Add VI-toolkit #

##################

#Add-PSsnapin VMware.VimAutomation.Core

#Initialize-VIToolkitEnvironment.ps1

connect-VIServer $vcserver

#############

  1. Variables #

#############

$filelocation="c:\VMpillar.htm"

$vcversion = get-view serviceinstance

$snap = get-vm | get-snapshot

$date=get-date

#############################

  1. Add Text to the HTML file #

#############################

ConvertTo-Html –title "Pillar VMware report " –body "

Pillar VMware report

" -head "" | Out-File $filelocation
ConvertTo-Html –title "Pillar VMware report " –body "

Date and time

",$date -head "" | Out-File -Append $filelocation
ConvertTo-Html –title "Pillar VMware report " –body "

VMWare vcenter $vcserver

" -head "" | Out-File -Append $filelocation

#

#####################

  1. VMware VC version #

######################

$vcversion.content.about | select Version, Build, FullName | ConvertTo-Html –title "VMware VirtualCenter version" –body "

VMware VC version.

" -head "" |Out-File -Append $filelocation

#######################

  1. 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 "

VMware ESX server Hardware configuration.

" -head "" | Out-File -Append $filelocation

#######################

  1. 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 "

$cluster cluster .

" -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

}

#############

  1. Snapshots #

#############

$snap | select vm, name,created,description | ConvertTo-Html –title "Snaphots active" –body "

Snapshots active.

" -head ""| Out-File -Append $filelocation

#################################

  1. VMware CDROM connected to VMs #

#################################

Get-vm | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" } } | Select Name | ConvertTo-Html –title "CDROMs connected" –body "

CDROMs connected.

" -head ""|Out-File -Append $filelocation

#########################################

  1. 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 "

Floppy drives connected.

" -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

}

  1. 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)

  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 "

Virtual Machine information.

" `
-head "" | `

Out-File -Append $filelocation

###############################

  1. 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 "

VMware timesync not enabled.

" -head "" | Out-File -Append $filelocation

########################################################

  1. 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

}

  1. Export the output

$myColCurrent | ConvertTo-Html –title "Datastore Information" –body "

Datastore Information.

" -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 "

RDM information.

" -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 "

Datastore with less than 10% free .

" -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 "

VM's that average over 75% memory usage .

" -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 "

Hosts that average over 75% memory usage .

" -head "" | Out-File -Append $filelocation

##############################

  1. Disconnect session from VC #

##############################

disconnect-viserver -confirm:$false

##########################

  1. 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

http://www.ttgapers.com

Version history
Revision #:
1 of 1
Last update:
‎07-07-2009 12:38 PM
Updated by: