In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Generation of html report based on css style of ConvertTo-Htm and specified cell effect
PowerShell itself has a simple but useful command ConvertTo-Htm that converts the entire object to HTML format. In fact, as a basic function, he can already implement some beautiful interfaces. But it is still too basic to meet the needs of most users.
On the one hand, whether the Html style can be beautiful css. Also, how to specify the effect of a specific cell to make the user experience better. For example, you want to mark all the contents of the Item5 column as ERR in red.
There are such functions on the Internet, but unfortunately there is a charge and no source code is provided. I realized the above idea after transformation on the basis of ConvertTo-Htm. The source code is provided for your reference.
The source code is as follows:
Function Set-CellColor {$HTML = $HTML | Set-CellColor Server green-Filter "server-eq 'dc2'" PS C:\ > $HTML | Set-CellColor Path Yellow-Filter "Path-like"* memory*" | Out-File c:\ Test\ colortest.html Takes a collection ofobjects in $Data, sorts on the property Server and converts to HTML. From there we set the "CookedValue" property to red if it's greater then 1. We then send the HTML through Set-CellColor again, this time setting theServer cell to green if it's "dc2". One more time through Set-CellColor turns the Path cell toYellow if it contains the word "memory" in it. .EXAMPLE $HTML = $Data | sort server | ConvertTo-html-head $header | Set-CellColor cookedvalue red-Filter "cookedvalue-gt 1"-Row Now, if the cookedvalueproperty is greater than 1 the function will highlight the entire row red. .notes Author: Martin Pugh Twitter: @ thesurlyadm1n Spiceworks: Martin9700 Blog: www.thesurlyadmin.com Changelog: 1.5 Added ability to set row colorwith-Row switch instead of the individual cell 1.03 Added error message in case the$Property field cannot be found in the table Header 1.02 Added some additional text tohelp. Added some error trapping around$Filter creation. 1.01 Added verbose output 1.0 Initial Release .link http://community.spiceworks.com/scripts/show/2450-change-cell-color-in-html-table-with-powershell-set-cellcolor # > [CmdletBinding ()] Param ([Parameter (Mandatory,Position=0)] [string] $Property, [Parameter (Mandatory,Position=1)] [string] $Color [Parameter (Mandatory,ValueFromPipeline)] [Object []] $InputObject, [Parameter (Mandatory)] [string] $Filter [switch] $Row) Begin {Write-Verbose "$(Get-Date): Function Set-CellColor begins" If ($Filter) {If ($Filter.ToUpper (). IndexOf ($Property.ToUpper ()-ge 0) {$Filter = $Filter.ToUpper () .Replace ($Property.ToUpper ()) "`$Value") Try {[scriptblock] $Filter = [scriptblock]:: Create ($Filter)} Catch {Write-Warning "$(Get-Date):"$Filter"caused an error, stoppingscript!" Write-Warning$Error [0] Exit}} Else {Write-Warning "Could not locate$Property in the Filter, which is required. Filter: $Filter "Exit}} Process {ForEach ($Line in$InputObject) {If ($Line.IndexOf (" (. *?)'- AllMatches $Index = 0 ForEach ($Match in$Search.Matches) {If ($Match.Groups [1] .value-eq $Property)) {Break} $Index + +} If ($Index-eq$Search.Matches.Count) {Write-Warning "$(Get-Date): Unable tolocate property: $Property in table header" Exit} Write-Verbose "$(Get-) Date): $Property column found at index: $Index "} If ($Line-match" (. *?)'- AllMatches $Value = $Search.Matches [$Index] .groups [1] .value-as [double] If (- not $Value) {$Value = $Search.Matches [$Index] .groups [1] .value} If (Invoke-Command$Filter) {If ($Row) {Write-Verbose "$(Get-Date): Criteriamet! Changing row to $Color... " If ($Line-match "") {$Line = $Line- replace "
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.