Automation

 View Only
  • 1.  Highlight values greater than a percentage

    Posted Sep 13, 2022 03:18 PM

    This Sritpt verify Datastorage and see the percentage to Used Space:

    Get-Datastore | Select Name, @{N=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}}, CapacityGB, @{N=”ProvisionedGB”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}}, @{N='Used Space(%)';E={[math]::Round((($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100),1)}} | foreach {if ('Used Space(%)' + 20 -ge "90") {$_ -replace "<tr>","<tr bgcolor=yellow>"} elseif( -gt "95"){$_ -replace "<tr>","<tr bgcolor=red>"}else{$_} } | Export-Csv "C:\Scripts\checks.csv"

    But i need highlight to Yellow if Used Space greater to 90% and Red if Used Space greater 95%. It doesn't work. 



  • 2.  RE: Highlight values greater than a percentage

    Posted Sep 13, 2022 04:17 PM

    In a CSV file you can't do highlighting of rows and/or columns.

    From your code it looks as if you took a snippet that produces HTML code.
    There you can have highlighting with that method.



  • 3.  RE: Highlight values greater than a percentage

    Posted Sep 14, 2022 02:41 PM

    Is correct my sript is HTML code, use CSV files to probe correct result. This is my real code:

    $body2 = Get-Datastore | Select Name, @{N=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}}, CapacityGB, @{N=”ProvisionedGB”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}}, @{N='Used Space(%)';E={[math]::Round((($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100),1)}} | foreach {if ('Used Space(%)' + 20 -ge "90") {$_ -replace "<tr>","<tr bgcolor=yellow>"} elseif( -gt "95"){$_ -replace "<tr>","<tr bgcolor=red>"}else{$_} } | ConvertTo-Html -PreContent "<h2>Data Storage vCenter: </h2>" | Out-String



  • 4.  RE: Highlight values greater than a percentage
    Best Answer

    Posted Sep 14, 2022 03:54 PM

    That will not work I'm afraid, you are replacing HTML tags before the actual ConvertTo-Html cmdlet.
    There are no HTML tags at that moment.

    Also, you can't refer to properties after the ConvertTo-Html cmdlet, the stream is a number of text lines.

    An easier way is to mark the calculated properties, and then inject the colour code after the ConvetTo-Html.

    Something like this for example



  • 5.  RE: Highlight values greater than a percentage

    Posted Sep 14, 2022 09:34 PM

    Thanks, is Great.