Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Set-AlternatingRows {
- <#
- .SYNOPSIS
- Simple function to alternate the row colors in an HTML table
- .DESCRIPTION
- This function accepts pipeline input from ConvertTo-HTML or any
- string with HTML in it. It will then search for <tr> and replace
- it with <tr class=(something)>. With the combination of CSS it
- can set alternating colors on table rows.
- CSS requirements:
- .odd { background-color:#ffffff; }
- .even { background-color:#dddddd; }
- Classnames can be anything and are configurable when executing the
- function. Colors can, of course, be set to your preference.
- This function does not add CSS to your report, so you must provide
- the style sheet, typically part of the ConvertTo-HTML cmdlet using
- the -Head parameter.
- .PARAMETER Line
- String containing the HTML line, typically piped in through the
- pipeline.
- .PARAMETER CSSEvenClass
- Define which CSS class is your "even" row and color.
- .PARAMETER CSSOddClass
- Define which CSS class is your "odd" row and color.
- .EXAMPLE $Report | ConvertTo-HTML -Head $Header | Set-AlternateRows -CSSEvenClass even -CSSOddClass odd | Out-File HTMLReport.html
- $Header can be defined with a here-string as:
- $Header = @"
- <style>
- TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
- TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
- TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
- .odd { background-color:#ffffff; }
- .even { background-color:#dddddd; }
- </style>
- "@
- This will produce a table with alternating white and grey rows. Custom CSS
- is defined in the $Header string and included with the table thanks to the -Head
- parameter in ConvertTo-HTML.
- .NOTES
- Author: Martin Pugh
- Twitter: @thesurlyadm1n
- Spiceworks: Martin9700
- Blog: www.thesurlyadmin.com
- Changelog:
- 1.1 Modified replace to include the <td> tag, as it was changing the class
- for the TH row as well.
- 1.0 Initial function release
- .LINK
- http://community.spiceworks.com/scripts/show/1745-set-alternatingrows-function-modify-your-html-table-to-have-alternating-row-colors
- .LINK
- http://thesurlyadmin.com/2013/01/21/how-to-create-html-reports/
- #>
- [CmdletBinding()]
- Param(
- [Parameter(Mandatory,ValueFromPipeline)]
- [string]$Line,
- [Parameter(Mandatory)]
- [string]$CSSEvenClass,
- [Parameter(Mandatory)]
- [string]$CSSOddClass
- )
- Begin {
- $ClassName = $CSSEvenClass
- }
- Process {
- If ($Line.Contains("<tr><td>"))
- { $Line = $Line.Replace("<tr>","<tr class=""$ClassName"">")
- If ($ClassName -eq $CSSEvenClass)
- { $ClassName = $CSSOddClass
- }
- Else
- { $ClassName = $CSSEvenClass
- }
- }
- Return $Line
- }
- }
- function ToObject {
- param(
- [Parameter(
- Position=0,
- Mandatory=$false,
- ValueFromPipeline=$true,
- ValueFromPipelineByPropertyName=$true)
- ]
- [Alias('Command')]
- [string]$cmd
- )
- $collection = @()
- $item = $null
- switch -regex (Invoke-Expression $cmd)
- {
- "^Record\s#\d+$"
- {
- if ($item) {$collection += $item}
- $item = New-Object System.Object
- }
- "^(?<name>\w+):\s(?<value>.*)"
- {
- if ($Matches.Name -ne "Executing")
- {
- $item | Add-Member -Type NoteProperty -Name $Matches.Name -Value $Matches.Value
- }
- }
- }
- if ($item) {$collection += $item}
- return $collection
- }
- try {asnp mclipssnapin -ErrorAction Stop} catch {Write-Host "McliPSSnapIn required" -f Red;break}
- $a = @"
- <style>
- TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;width: 95%}
- TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
- TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
- .odd { background-color:#ffffff; }
- .even { background-color:#dddddd; }
- </style>
- "@
- ###### edit the path of the $htm######
- $htm = "\\server\share\info.html"
- if (Test-Path $htm) {ri $htm -Force}
- ("mcli-get server" | ToObject).servername | %{
- "mcli-get serverstatus -p servername=$_" | ToObject | select @{n="PVS Server";e={$_.servername}},@{n="Status";e={if ($_.status -eq "1"){"Active"} else {"Inactive"}}},@{n="Connected Devices";e={$_.devicecount}}
- } | ConvertTo-Html -head $a | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $htm -Encoding ascii -Append
- "<br><br>" | Out-File $htm -Encoding ascii -Append
- "mcli-get diskinfo" | ToObject | select @{n="vDisk";e={$_.disklocatorname}},@{n="Active Devices";e={$_.devicecount}},@{n="High Availability";e={if ($_.haenabled -eq "1") {$true} else {$false}}},`
- @{n="Write Cache Type";e={if ($_.writecachetype -eq "0") {"Private/Maint"} elseif ($_.writecachetype -eq "7") {"Cache to PVS Server Persistent"} elseif ($_.writecachetype -eq "1") {"Cache to PVS Server"}`
- elseif ($_.writecachetype -eq "3") {"Cache to Device RAM"} elseif ($_.writecachetype -eq "8") {"Cache to Device Hard Disk Persistent"} elseif ($_.writecachetype -eq "9") {"Cache to RAM with Overflow to Disk"}`
- elseif ($_.writecachetype -eq "4") {"Cache on HDD"}}} | ConvertTo-Html -head $a | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $htm -Encoding ascii -Append
- "<br><br>" | Out-File $htm -Encoding ascii -Append
- "mcli-get diskinfo" | ToObject | select disklocatorname,sitename,storename | %{
- $disk = $_.disklocatorname
- $site = $_.sitename
- $store = $_.storename
- "mcli-get diskversion -p disklocatorname=$disk,sitename=$site,storename=$store" | ToObject | select @{n="Disk Name";e={$disk}},@{n="Version";e={$_.version}},`
- @{n="Disk Status";e={if ($_.goodinventorystatus -eq "0" -and $_.access -ne "1") {"Not Synced"} elseif ($_.access -ne "1") {"Synced"} elseif ($_.access -eq "1") {"Read/Write"}}}
- } | ConvertTo-Html -head $a | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $htm -Encoding ascii -Append
- "<br><br>" | Out-File $htm -Encoding ascii -Append
- "mcli-get farm" | ToObject | select @{n="Farm Name";e={$_.farmname}},@{n="License Server";e={$_.licenseserver}},@{n="License Server Port";e={$_.licenseserverport}},`
- @{n="Database Server Name";e={$_.databaseservername}},@{n="Database Instance Name";e={if ($_.databaseinstancename -ne "") {$_.databaseinstancename} else {"Default"}}},`
- @{n="Database Name";e={$_.databasename}},@{n="Offline DB Enabled";e={if ($_.offlinedatabasesupportenabled -eq "1") {$true} else {$false}}} | ConvertTo-Html -head $a | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $htm -Encoding ascii -Append
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement