Home > other >  Change the text color with HTML and CSS using PowerShell
Change the text color with HTML and CSS using PowerShell

Time:07-07

I'm confused on how to change the color of the text without using Write-Host and the color should be change in the HTML output.

green

$overallStatus = ''
    
    
    if(($isDBConnected.Equals('Connected Successfully')) -and ($isCMConnected.Equals('Connected Successfully'))){
    $overallStatus = 'GREEN'
    }
    else{
      $overallStatus = 'Red'
       $overallStatus
       }
   

and this is my composition for html

for($a=0; $a -le $notiftemplate.Length; $a  ){
  
     switch -Regex ($notiftemplate[$a]){ 
         "\[status\]"{
         $notiftemplate[$a] = $notiftemplate[$a] -replace "\[status\]",$overallStatus
         break;
         } 
    }
     

I tried this but it's not working.:

 $overallStatus = @{"<td style='padding-left:5pt;'> <b> [status] </b></td>"}

CodePudding user response:

Try this if your code have the right syntax and you don't use tables in html and there is no more code because of the TD tag:

 $overallStatus = @"<span style='padding-left:5pt;color:green;font-weight:bold;'> GREEN </span>"@

or

 $overallStatus = '<span style="color:green;">GREEN</span>'

If there is more code for the table, because of the td tag use:

 $overallStatus = @"<td style='padding-left:5pt;color:green;font-weight:bold;'> GREEN </td>"@
  • Related