You can try this..; i can't test it at home, but it should work without few minors modifications
function Set-AlternatingCSSClasses {
param(
[string]$HTMLFragment,
[string]$CSSEvenClass,
[string]$CssOddClass
)
[xml]$xml = $HTMLFragment
$table = $xml.SelectSingleNode('table')
$classname = $CSSOddClass
foreach ($tr in $table.tr) {
if ($classname -eq $CSSEvenClass) {
$classname = $CssOddClass
} else {
$classname = $CSSEvenClass
}
$class = $xml.CreateAttribute('class')
$class.value = $classname
$tr.attributes.append($class) | Out-null
}
$xml.innerxml | out-string
}
Function Report-Datastore {
$output = @()
Get-Datastore | % {
# | Select-Object -ExpandProperty Name
# $array1 += Get-Datastore | Select-Object -ExpandProperty FreeSpaceGB
# $array2 += Get-Datastore | Select-Object -ExpandProperty CapacityGB
$props = [ordered]@{'Name'=$_.Name;
'UsedSpace'=[math]::Round(($_.CapacityGB - $_.FreeSpaceGB),2);
'PercFree'=[math]::Round((100 * ($_.FreeSpaceGB/$_.CapacityGB)),0)}
$output += New-Object -TypeName PSCUstomObject -Property $props
}
}
$msg.Subject = "vCenter Datastore Health CompanyvCenter"
$style = @"
<style>
body {
color:#333333;
font-family:Calibri,Tahoma;
font-size: 10pt;
}
h1 {
text-align:center;
}
h2 {
border-top:1px solid #666666;
}
th {
font-weight:bold;
color:#eeeeee;
background-color:#333333;
}
.odd { background-color:#ffffff; }
.even { background-color:#dddddd; }
</style>
"@
Connect-VIServer $vcserver
$html_DS = Report-Datastore |
Sort-Object PercFree |
ConvertTo-HTML -Fragment |
Out-String |
Set-AlternatingCSSClasses -CSSEvenClass 'even' -CssOddClass 'odd'
$html_DS = "<h2>Datastores</h2>$html_DS"
$params = @{'Head'="<title>vCenter Datastore Health CompanyvCenter</title>$style";
'PreContent'="<h1>Datastore HealthCheck CompanyvCenter</h1>";
'PostContent'=$html_DS}
$msg.Body = ConvertTo-HTML @params
$msg.Attachments.Add($att1)
$msg.IsBodyHTML = $true
$smtp.Send($msg)
$att1.Dispose()
Disconnect-VIServer $vcserver -Confirm:$false