{"id":16480898,"url":"https://github.com/ramblingcookiemonster/pshtmltable","last_synced_at":"2025-03-21T07:30:30.572Z","repository":{"id":72634509,"uuid":"66588277","full_name":"RamblingCookieMonster/PSHTMLTable","owner":"RamblingCookieMonster","description":"PowerShell module to spice up ad hoc notifications and reports","archived":false,"fork":false,"pushed_at":"2017-06-22T01:02:33.000Z","size":213,"stargazers_count":38,"open_issues_count":1,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T22:24:21.484Z","etag":null,"topics":["html","powershell","powershell-modules","reporting","table","visualization"],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RamblingCookieMonster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-08-25T19:49:15.000Z","updated_at":"2024-09-13T11:59:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"f9b039b1-7cc5-4e89-8dab-25540bc886c5","html_url":"https://github.com/RamblingCookieMonster/PSHTMLTable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RamblingCookieMonster%2FPSHTMLTable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RamblingCookieMonster%2FPSHTMLTable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RamblingCookieMonster%2FPSHTMLTable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RamblingCookieMonster%2FPSHTMLTable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RamblingCookieMonster","download_url":"https://codeload.github.com/RamblingCookieMonster/PSHTMLTable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244757098,"owners_count":20505330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","powershell","powershell-modules","reporting","table","visualization"],"created_at":"2024-10-11T13:05:41.440Z","updated_at":"2025-03-21T07:30:30.156Z","avatar_url":"https://github.com/RamblingCookieMonster.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"PSHTMLTable\n==============\n\nThis is an old set of functions used to generate HTML tables, and highlight cells within them on demand.\n\nOne of PowerShell�s major strong points is its ability to interface with a variety of technologies and data sources.  This makes it a great candidate for sending ad hoc notifications or generating HTML based reports.  The attached functions can be used to spice up various notifications, reports, or other HTML generated by PowerShell.\n\nA quick example showing a standard SCOM alert, and a SCOM alert generated using PSHTMLTable functions.  The latter is a bit more helpful!\n\n**Plain SCOM Alert**:\n\n[![plain alert](/Media/scom_plain.png)](/Media/scom_plain.png)\n\n**PSHTMLTable SCOM Alert**:\n\n[![scom spicy](/Media/scom_spicy.png)](/Media/scom_spicy.png)\n\n## Instructions\n\n```powershell\n# One time setup\n    # Download the repository\n    # Unblock the zip\n    # Extract the PSHTMLTable folder to a module path (e.g. $env:USERPROFILE\\Documents\\WindowsPowerShell\\Modules\\)\n\n    #Simple alternative, if you have PowerShell 5, or the PowerShellGet module:\n        Install-Module PSHTMLTable\n\n# Import the module.\n    Import-Module PSHTMLTable    #Alternatively, Import-Module \\\\Path\\To\\PSHTMLTable\n\n# Get commands in the module\n    Get-Command -Module PSHTMLTable\n```\n\n## Examples\n\n### Simple Example\n\nThis illustrates creating a webpage with several Process related stats, using all of the functions in PSHTMLTable\n\n```powershell\n#gather 20 events from the system log and pick out a few properties\n    $events = Get-EventLog -LogName System -Newest 20 | select TimeGenerated, Index, EntryType, UserName, Message\n\n#Create the HTML table without alternating rows, colorize Warning and Error messages, highlighting the whole row.\n    $eventTable = $events | New-HTMLTable -setAlternating $false |\n        Add-HTMLTableColor -Argument \"Warning\" -Column \"EntryType\" -AttrValue \"background-color:#FFCC66;\" -WholeRow |\n        Add-HTMLTableColor -Argument \"Error\" -Column \"EntryType\" -AttrValue \"background-color:#FFCC99;\" -WholeRow\n\n#Build the HTML head, add an h3 header, add the event table, and close out the HTML\n    $HTML = New-HTMLHead\n    $HTML += \"\u003ch3\u003eLast 20 System Events\u003c/h3\u003e\"\n    $HTML += $eventTable | Close-HTML\n\n#test it out\n    set-content C:\\test.htm $HTML\n    \u0026 'C:\\Program Files\\Internet Explorer\\iexplore.exe' C:\\test.htm\n```\n\n[![example output](/Media/e2_events.png)](/Media/e2_events.png)\n\n### Complex Example\n\nThis illustrates creating a webpage with several Process related stats, using all of the functions in PSHTMLTable\n\n```powershell\n#This example demonstrates using the New-HTMLHead, New-HTMLTable, Add-HTMLTableColor, ConvertTo-PropertyValue and Close-HTML functions\n\n#get processes to work with\n    $processes = Get-Process\n\n#Build HTML header\n    $HTML = New-HTMLHead -title \"Process details\"\n\n#Add CPU time section with top 10 PrivateMemorySize processes.  This example does not highlight any particular cells\n    $HTML += \"\u003ch3\u003eProcess Private Memory Size\u003c/h3\u003e\"\n    $HTML += New-HTMLTable -inputObject $($processes | sort PrivateMemorySize -Descending | select name, PrivateMemorySize -first 10)\n\n#Add Handles section with top 10 Handle usage.\n$handleHTML = New-HTMLTable -inputObject $($processes | sort handles -descending | select Name, Handles -first 10)\n\n    #Add highlighted colors for Handle count\n\n        #build hash table with parameters for Add-HTMLTableColor.  Argument and AttrValue will be modified each time we run this.\n        $params = @{\n            Column = \"Handles\" #I'm looking for cells in the Handles column\n            ScriptBlock = {[double]$args[0] -gt [double]$args[1]} #I want to highlight if the cell (args 0) is greater than the argument parameter (arg 1)\n            Attr = \"Style\" #This is the default, don't need to actually specify it here\n        }\n\n        #Add yellow, orange and red shading\n        $handleHTML = Add-HTMLTableColor -HTML $handleHTML -Argument 1500 -attrValue \"background-color:#FFFF99;\" @params\n        $handleHTML = Add-HTMLTableColor -HTML $handleHTML -Argument 2000 -attrValue \"background-color:#FFCC66;\" @params\n        $handleHTML = Add-HTMLTableColor -HTML $handleHTML -Argument 3000 -attrValue \"background-color:#FFCC99;\" @params\n\n    #Add title and table\n    $HTML += \"\u003ch3\u003eProcess Handles\u003c/h3\u003e\"\n    $HTML += $handleHTML\n\n#Add process list containing first 10 processes listed by get-process.  This example does not highlight any particular cells\n    $HTML += New-HTMLTable -inputObject $($processes | select name -first 10 ) -listTableHead \"Random Process Names\"\n\n#Add property value table showing details for PowerShell ISE\n    $HTML += \"\u003ch3\u003ePowerShell Process Details PropertyValue table\u003c/h3\u003e\"\n    $processDetails = Get-process powershell_ise | select name, id, cpu, handles, workingset, PrivateMemorySize, Path -first 1\n    $HTML += New-HTMLTable -inputObject $(ConvertTo-PropertyValue -inputObject $processDetails)\n\n#Add same PowerShell ISE details but not in property value form.  Close the HTML\n    $HTML += \"\u003ch3\u003ePowerShell Process Details object\u003c/h3\u003e\"\n    $HTML += New-HTMLTable -inputObject $processDetails | Close-HTML\n\n#write the HTML to a file and open it up for viewing\n    set-content C:\\test.htm $HTML\n    \u0026 'C:\\Program Files\\Internet Explorer\\iexplore.exe' C:\\test.htm\n```\n\n[![example output](/Media/e1_process.png)](/Media/e1_process.png)\n\n\n### Pester Example\n```powershell\n# Invoke pester and store the results so that they can be referenced multiple times\n$results = Invoke-Pester -show none -passthru\n\n# Format cells where the value is greater than 0\n$params = @{\n    ScriptBlock = {$args[0] -gt 0}\n}\n\n# Create a summary table and add spaces into the column names for asthetics, adding colours for passed and failed tests\n$summaryTable = $results | Select-Object `\n     @{Name=\"Passed Count\";Expression={$_.PassedCount}},\n     @{Name=\"Failed Count\";Expression={$_.FailedCount}},\n     @{Name=\"Skipped Count\";Expression={$_.SkippedCount}},\n     @{Name=\"Pending Count\";Expression={$_.PendingCount}},\n     @{Name=\"Total Count\";Expression={$_.TotalCount}} | New-HtmlTable |\n    Add-HTMLTableColor -Argument \"Failed\" -Column \"Failed Count\" -AttrValue \"background-color:#ffb3b3;\" @params |\n    Add-HTMLTableColor -Argument \"Passed\" -Column \"Passed Count\" -AttrValue \"background-color:#c6ffb3;\" @params\n\n#Compose the html adding headers\n$HTML = New-HTMLHead\n$HTML += \"\u003ch3\u003ePost Build Test Summary\u003c/h3\u003e\"\n$HTML += $summaryTable\n$HTML += \"\u003ch3\u003ePost Build Test Results\u003c/h3\u003e\"\n\n# Create a seperate table for each describe block\nforeach ($section in ($results |Select-Object -ExpandProperty TestResult | Select-Object Describe -Unique)) {\n    # Add a title based on the descibe block\n    $HTML += (\"\u003ch4\u003e{0}\u003c/h4\u003e\" -f $section.Describe)\n    $HTML += $results | Select-Object -ExpandProperty TestResult | Where-Object -FilterScript { $_.Describe -eq $section.Describe } |\n        Select-Object Context, Name, Result |\n        New-HtmlTable |\n            Add-HTMLTableColor -Argument \"Failed\" -Column \"Result\" -AttrValue \"background-color:#ffb3b3;\" |\n            Add-HTMLTableColor -Argument \"Passed\" -Column \"Result\" -AttrValue \"background-color:#c6ffb3;\"\n}\n\n$HTML += \"\" | Close-HTML\n\n#test it out\nset-content C:\\test.html $HTML\n\u0026 'C:\\Program Files\\Internet Explorer\\iexplore.exe' C:\\test.html\n```\n\n[![example output](/Media/pester_advanced.png)](/Media/pester_advanced.png)\n\n## Functions\n\nPSHTMLTable includes several functions:\n\n* ConvertTo-PropertyValue - Convert an object with various properties into an array of property,value pairs\n* New-HTMLHead - Starts building HTML including internal style sheet (leaves body, html tags open)\n* New-HTMLTable - Create an HTML table from one or more objects\n* Add-HTMLTableColor - Colorize cells or rows in an HTML table, or add other inline CSS\n* CloseHTML - Close out the body and html tags\n\n## Notes\n\nThis was written during my early days with PowerShell - pull requests would be welcome!\n\nFor more details, stop by [the old blog post](http://ramblingcookiemonster.wordpress.com/2013/08/06/powershell-and-tables/) on this!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framblingcookiemonster%2Fpshtmltable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Framblingcookiemonster%2Fpshtmltable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framblingcookiemonster%2Fpshtmltable/lists"}