PSWriteHTML

repository·master·Indexed 20 days ago

https://github.com/evotecit/pswritehtml

A PowerShell module for generating high-quality HTML reports, web pages, and emails without requiring knowledge of HTML, CSS, or JavaScript. It provides a hierarchical approach to building documents using cmdlets like New-HTML, Save-HTML, and Out-HtmlView, and includes specialized tools for data visualization (charts, gauges, timelines), tables, and formatted email generation.

Tokens
101K
Snippets
284
Records
465
Agent score
65%

What's inside PSWriteHTML

  1. Overview of PSWriteHTML

    master
    PSWriteHTML is a PowerShell module designed to generate high-quality HTML reports, web pages, and emails. It abstracts the complexities of HTML, CSS, and JavaScript, allowing users to create professional visual outputs using only basic PowerShell knowledge.
  2. Use New-HTMLTag to control the page head

    master

    The New-HTMLTag function allows you to inject custom HTML into the document stream. This is the recommended pattern when you need to manage the <head> section manually, such as adding custom viewport settings, character sets, or other metadata that high-level report helpers might not support directly.

    New-HTMLTag -Tag 'meta' -Attributes @{ name = 'viewport'; content = 'width=device-width, initial-scale=1' } -NoClosing
  3. Configure tree node hierarchy using -Children

    master

    To create a nested tree structure, use the -Children parameter. This parameter accepts a ScriptBlock containing further calls to New-HTMLTreeNode. If a node has children, it is typically used in conjunction with the -Folder switch to represent a directory-like structure.

    New-HTMLTreeNode -Title "Parent" -Folder -Children {
        New-HTMLTreeNode -Title "Child 1"
        New-HTMLTreeNode -Title "Child 2"
    }
  4. Create Diagram Nodes using different parameter sets

    master

    The New-DiagramNode cmdlet uses different parameter sets depending on the type of node you want to create. You must choose one of the following styles:

    Shape

    Uses the -Shape parameter to create geometric nodes. Supported shapes: circle, dot, diamond, ellipse, database, box, square, triangle, triangleDown, text, star, hexagon.

    Image

    Uses the -Image parameter to display a graphic.

    • -ImageType: Choose between squareImage or circularImage.
    • -BrokenImages: String to handle broken image paths.

    FontAwesome (Solid, Regular, Brands)

    Uses FontAwesome icons as nodes.

    • -IconSolid: For the FontAwesomeSolid set.
    • -IconRegular: For the FontAwesomeRegular set.
    • -IconBrands: For the FontAwesomeBrands set (requires -IconBrands string).
    • -IconAsImage: Switch to render the icon as an image instead of a font icon.
    • -IconColor: Sets the color of the icon.
  5. Ensure reproducible layouts with RandomSeed

    master

    When not using a hierarchical layout, nodes are positioned randomly, meaning the result changes every time. To ensure the same layout is generated every time, provide a specific integer to the -RandomSeed parameter.

    Tip: If you find a layout you like, you can use the getSeed() method to find the seed used, then hardcode it into your script for reproducibility.

  6. Understand the PSWriteHTML website content structure

    master

    The PSWriteHTML website content is organized into specific directories to separate documentation from examples. This structure is used by the Evotec website to import and display project-specific information.

    • content/project-docs/: Contains short project documentation pages (displayed at /projects/pswritehtml/docs/).
    • content/examples/: Contains curated website examples (displayed at /projects/pswritehtml/examples/).
    • WebsiteArtifacts/: A directory generated by the build process; it is intentionally ignored by Git.
  7. Manage physics stabilization settings

    master

    Stabilization is the process where the physics engine runs until the network reaches a steady state. You can control this behavior using:

    • -StabilizationEnabled: Toggles stabilization. Defaults to $true if any physics properties are defined.
    • -Stabilizationfit: If $true, the view zooms to fit all nodes once stabilization finishes.
    • -Stabilizationiterations: The maximum number of iterations to attempt stabilization.
    • -StabilizationonlyDynamicEdges: If $true, only dynamic smooth edges are stabilized, freezing visible nodes in place.
    • -StabilizationupdateInterval: Determines how many iterations occur before the stabilizationProgress event is triggered (useful for showing loading bars).
    • -AdaptiveTimestep: If enabled, the timestep is intelligently adapted during the stabilization stage to decrease time. This requires stabilization to be enabled.
  8. Select FontAwesome icon sets for New-HTMLTab

    master

    The New-HTMLTab cmdlet uses different parameters depending on which FontAwesome icon style you want to use. You must choose one of the following sets:

    1. FontAwesomeBrands: Use the -IconBrands <string> parameter.
    2. FontAwesomeSolid: Use the -IconSolid <string> parameter.
    3. FontAwesomeRegular: Use the -IconRegular <string> parameter.

    In all cases, you can use tab completion in PowerShell to see available icon options.

  9. Understand PSWriteHTML usage modes (Online vs Offline)

    master

    The module utilizes several 3rd party JavaScript and CSS libraries (such as DataTables, ApexCharts, and Font Awesome) to provide advanced functionality. You can use the module in two ways depending on your requirements:

    1. Online Mode (Links): Uses links to external CSS/JS files. This results in cleaner, smaller HTML files but requires an internet connection to render correctly.
    2. Offline Mode (Inline - Default): Inlines all necessary code directly into the HTML. This makes the HTML files much larger but allows the reports to be viewed entirely offline without external dependencies.
  10. Configure New-HTML resource loading (Online vs Local)

    master

    The -Online switch determines how CSS and JavaScript resources are loaded:

    • -Online (Enabled): CSS and JS files are loaded from a CDN. This results in much smaller local HTML files and is recommended for web-hosted reports.
    • -Online (Disabled/Default): All CSS and JS are embedded directly into the single HTML file. This makes the file very large but allows the report to work offline without any external dependencies.
  11. How New-HTML works as a building block

    master

    In PSWriteHTML, New-HTML acts as the container or 'root' for your report. Most other cmdlets (like New-HTMLSection, New-HTMLPanel, New-HTMLTable, etc.) are designed to be called inside the script block provided to New-HTML.

    Think of New-HTML as the document initialization step. Without providing an -HtmlData script block, the cmdlet has no content to generate. Once initialized, you compose your report by nesting specialized cmdlets within that block to create sections, panels, charts, and tables.

    New-HTML { 
        # All other PSWriteHTML cmdlets go here
        New-HTMLSection { ... }
        New-HTMLPanel { ... }
    } -FilePath "report.html"