The "@ has to be at the very start of the line in order to work
here is a version without CSS...
Function Report-Datastore {
$output = @()
Get-Datastore | % {
$props = [ordered]@{'Name'=$_.Name;
'UsedSpace'=[math]::Round(($_.CapacityGB - $_.FreeSpaceGB),2);
'PercFree'=[math]::Round((100 * ($_.FreeSpaceGB/$_.CapacityGB)),0)}
$output += New-Object -TypeName PSCUstomObject -Property $props
}
$output
}
$msg.Subject = "vCenter Datastore Health CompanyvCenter"
Connect-VIServer $vcserver
$html_DS = Report-Datastore |
Sort-Object PercFree |
ConvertTo-HTML -Fragment |
Out-String
$html_DS = "<h2>Datastores</h2>$html_DS"
$params = @{'Head'="<title>vCenter Datastore Health CompanyvCenter</title>";
'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