Solved

modify script to display red value in stylesheet

Posted on 2015-01-13
2
70 Views
Last Modified: 2015-01-27
Hello,

how to modify this script to display red, backups whose delta is greater than 0 ?


#Stylesheet for returning results

$style = '<style>'

$style = $style + 'BODY{background-color:peachpuff;}'

$style = $style + 'TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}'

$style = $style + 'TH{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:thistle;font-size:16}'

$style = $style+ 'TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:palegoldenrod;font-size:14}'

$style = $style + '</style>'



$Databases_Backups = invoke-sqlcmd @params -Query "Select ServerName,

    DatabaseName

    , case LastAbsoluteBackupDate

            when '1900-01-01 00:00:00' then 'Never Backed Up'

            else convert(varchar(20), LastAbsoluteBackupDate, 120)

            end as LastBackup

    , case LastAbsoluteBackupDate

            when '1900-01-01 00:00:00' then 'Never Backed Up'

            else convert(varchar,BackupDelta)

            end as BackupDelta

    from dbo.DatabaseBackups order by BackupDelta desc " | convertTo-Html -Head $style -Property ServerName, DatabaseName, LastBackup, BackupDelta | out-string;

Open in new window


Thanks

Regards
0
Comment
Question by:bibi92
2 Comments
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 40548152
PowerShell doesn't do something like this well.
You either have to manually generate the HTML, or when possible take the output from ConvertTo-HTML and do string replace operations to modify the HTML so it includes the HTML code for the formatting you desire.

Do you know what the HTML would look like to give you the output you want?  Since I don't want to research HTML code, if you can give sample output (i.e. HTML source that shows 3 rows of output) that includes the formatting you want it would help.

You might also try the function I found at
http://community.spiceworks.com/scripts/show/2450-change-cell-color-in-html-table-with-powershell-set-cellcolor
0
 

Author Closing Comment

by:bibi92
ID: 40574638
Thanks
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Synchronize a new Active Directory domain with an existing Office 365 tenant
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question