Hello,
I’m using below code to get disk space information for servers along with custom info in html format…
My question is how do I use html bgcolor property in ‘Check-DiskSta’ function for ‘C_PercentFreeGB’ and ‘D_PercentFreeGB’ column with red for <10% and orange for <15% free disk space value.
Thanks
$header = "
DiskSpace Report
Daily Health Check $strDate
"
#Disk information for all critical servers
Function Check-DiskStat()
{
$csvPath = ‘.\ServerInventory.csv’
$DiskReport = foreach ($Server in (Import-Csv $csvPath)) {
New-Object -TypeName PSObject -Property @{
ServerName = $Server.ServerName
Application = $Server.ServiceType
ServiceName = $Server.ServiceName
Environment = $Server.Env
C_SizeGB= $(Get-WmiObject Win32_logicaldisk -Filter "DriveType = 3" -ComputerName $Server.ServerName |
?{$_.deviceid -eq 'C:'} | Select @{Name="Size";Expression={[decimal]("{0:N0}" -f($_.size/1gb))}}).Size
C_FreeSpaceGB= $(Get-WmiObject Win32_logicaldisk -Filter "DriveType = 3" -ComputerName $Server.ServerName |
?{$_.deviceid -eq 'C:'} | Select @{Name="Size";Expression={[decimal]("{0:N0}" -f($_.freespace/1gb))}}).Size
C_PercentFreeGB= $(Get-WmiObject Win32_logicaldisk -Filter "DriveType = 3" -ComputerName $Server.ServerName |
?{$_.deviceid -eq 'C:'} | Select @{Name="Size";Expression={"{0,6:P0}" -f(($_.freespace/1gb) / ($_.size/1gb))}}).Size
D_SizeGB= $(Get-WmiObject Win32_logicaldisk -Filter "DriveType = 3" -ComputerName $Server.ServerName |
?{$_.deviceid -eq 'D:'} | Select @{Name="Size";Expression={[decimal]("{0:N0}" -f($_.size/1gb))}}).Size
D_FreeSpaceGB= $(Get-WmiObject Win32_logicaldisk -Filter "DriveType = 3" -ComputerName $Server.ServerName |
?{$_.deviceid -eq 'D:'} | Select @{Name="Size";Expression={[decimal]("{0:N0}" -f($_.freespace/1gb))}}).Size
D_PercentFreeGB= $(Get-WmiObject Win32_logicaldisk -Filter "DriveType = 3" -ComputerName $Server.ServerName |
?{$_.deviceid -eq 'D:'} | Select @{Name="Size";Expression={"{0,6:P0}" -f(($_.freespace/1gb) / ($_.size/1gb))}}).Size
}| select ServerName, Application, C_SizeGB, C_FreeSpaceGB, C_PercentFreeGB, D_SizeGB, D_FreeSpaceGB, D_PercentFreeGB
}
Return, $DiskReport
}
$dskrpt = Check-DiskStat
$Diskinformation = $dskrpt| ConvertTo-Html -Fragment -PreContent ‘Disk Information’ |Out-String
ConvertTo-Html -Head $header -PostContent $Diskinformation, $funout2, $funout3 -CssUri ‘F:\MyDocs\MyScripts\DailyHealthCheck\out.css’ | out-file $Result