I have found interesting code that highlights a rows in table if the output is not desired
Source - https://www.youtube.com/watch?v=QdK3qM5jnYw&feature=youtu.be
$headLinkcheck += @'
<style>
body
{
background-color:white;
font-family:Arial;
font-size:8pt;
}
td,th
{
border:1px solid black;
border-collapse:collapse;
}
th
{
color:white;
background-color:black;
}
table, tr, td, th {padding:5px; margin: 0px;}
table {margin-left:50px;width: 80%;height:35%}
.danger {background-color:yellow;font-weight:bold}
.warn {background-color:blue}
</style>
'@
Ok now i have code that checks webistes and their status
function GetSiteStatus(){
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[hashtable]$WebSiteInfo
)
process{
$Response = New-Object System.Collections.ArrayList
$WebSiteInfo.GetEnumerator() | %{
$Item = $_
try{
$status = Invoke-WebRequest -Uri $_.Value | %{
if(@('404','503','403') -match $_.StatusCode){
"$($Item.Key) The Site may be down, please check. - status is $($_.StatusCode)"
}else{
"OK"
}
}
$Response.Add([PSCustomObject]@{"Name"= $Item.Key; "Value"=$Item.Value; "Status"=$Status; "Link"=$($Item.value)}) | out-null
}catch{
$Status = "$($Item.Key), $_."
$Response.Add([PSCustomObject]@{"Name"= $Item.Key; "Value"=$Item.Value; "Status"=$Status; "Link"=$($Item.value)}) | out-null
}
}
return $Response
}
}
$html_url1 = @{
"Calendar" = "http:/";
} | GetSiteStatus | ConvertTo-Html -Head $headLinkcheck -Property Name,Value,Status,@{Label="Link";Expression={"<a href='$($_.Value)'>$($_.Name)</a>"}}
Add-Type -AssemblyName System.Web
[System.Web.HttpUtility]::HtmlDecode($html_url) | Out-File "\\servertest\xpbuild$\IT\Level0\scresult\servicecheck$global:servicecheckdate.htm" -Append # have to use it to creates clickable links
Now the last piece is second part of code which i found ,that checks each line in rows -theorically
[array]$html_url += $html_url1 i quess this might help code below to read values
[xml]$html = $html_url | ConvertTo-Html -Fragment
for ($i = 1; $i -le $html.table.tr.Count-1;$i++){
$class = $html.CreateAttribute("class")
if(($html.table.tr[$i].td[-1]) -ne "OK"){
$class.Value = "danger"
$html.table.tr[$i].attributes.append($class) | Out-Null
}
}
$body += @"
$($html.innerxml)
"@
Now the problem with this is i am not sure how to implement this last part to my code
I got variable- $html_url1 that contains all needed values from my function that checks webistes.
I am not sure how to add this piece - should I add it to my $html_url1 pipe? I tried and it fails. Can you suggest hopw to implement this ?