HTML Conditional formatting

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Biswajit Biswajit 2 years, 2 months ago.

  • Author
    Posts
  • #19225
    Profile photo of Biswajit
    Biswajit
    Participant

    Function RDPStatus {
    $Prop = [ordered]@{}
    $ComputerName = Get-Content C:\computers.txt -ReadCount 0
    $ErrorActionPreference = "Stop"
    foreach ($computer in $ComputerName)
    {
    Try {

    $Prop.Computername = GWMI win32_operatingsystem -cn $computer | select-object -ExpandProperty CSName
    $Network = GWMI -CN $computer -Class Win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"' | Select-Object -ExpandProperty IPAddress
    $Prop.IPadddress = $Network -join ','
    $Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
    $RegKey= $Reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server")
    $RDP = $Regkey.GetValue("fDenyTSConnections")

    if ($RDP -eq 1)
    {
    $Prop.RDP = "Disabled"

    }
    else
    {
    $Prop.RDP= "Enabled"
    }

    $Bios = GWMI win32_bios -cn $computer | Select-Object -ExpandProperty SerialNumber
    $Model= GWMI win32_computersystem -cn $computer | Select-Object -ExpandProperty Model
    $Prop.BiosSlNos =$Bios
    $Prop.Model = $Model

    New-Object PSObject -property $Prop
    }
    Catch

    {

    Add-Content "$computer is not reachable" -path $env:USERPROFILE\Desktop\UnreachableHosts.txt

    }

    }

    }

    #HTML Color Code
    #http://technet.microsoft.com/en-us/librProp/ff730936.aspx
    $a = ""
    $a = $a + "BODY{background-color:#DAA520;font-family:verdana;font-size:10pt;}"
    $a = $a + "TABLE{border-width: 2px;border-style: solid;border-color:#000000;border-collapse: collapse;}"
    $a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: #000000;background-color:#7FFF00;}"
    $a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: #000000;background-color:#FFD700;}"
    $a = $a + ""
    RDPStatus | ConvertTo-HTML -head $a -body "RDP Status" |
    Out-File $env:USERPROFILE\Desktop\RDPStatus.htm #HTML Output
    Invoke-Item $env:USERPROFILE\Desktop\RDPStatus.htm
    ____________________________________________________
    {
    $Prop.RDP = "Disabled" —- Need red color in background cell

    }
    else
    {
    $Prop.RDP= "Enabled"
    }
    _________________________________________________
    Thanks in advance

  • #19226
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Conditional cell formatting isn't easy with the native HTML cmdlets. Grab our free ebook, "Creating HTML Reports in PowerShell." It comes with an EnhancedHTML2 module that does this, and includes numerous examples.

  • #19232
    Profile photo of Biswajit
    Biswajit
    Participant

    Thanks Don 🙂

You must be logged in to reply to this topic.