Project

PSWriteHTML

Generate HTML reports, dashboards, and emails from PowerShell without writing HTML, CSS, or JavaScript.

Stars 1,019
Forks 115
Open issues 54
PowerShell Gallery downloads 7,576,901
Release v1.41.0
Language: PowerShell Updated: 2026-10-03
Command

New-HTMLCodeBlock

Module PSWriteHTML

Creates a new HTML code block with customizable settings for syntax highlighting.

Syntax

New-HTMLCodeBlock [-Code] <String> [[-Group] <String>] [[-Highlight] <String[]>] [[-LineOffset] <String>] [[-ShowLineNumbers] <Nullable`1>] [[-Style] <String>] [[-Theme] <String>] [[-Title] <String>] [<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

This function creates a new HTML code block with customizable settings for syntax highlighting. It allows you to specify the code language, theme, group, title, line numbers visibility, highlighted lines, and line numbering offset.

Examples

Authored help example

EXAMPLE 1

New-HTMLCodeBlock -Code "function greet() { return 'Hello, World!'; }" -Style 'javascript' -Theme 'monokai' -Group 'Functions' -Title 'Greeting Function' -Highlight 2,4-6 -ShowLineNumbers $true -LineOffset 1

Creates a new HTML code block displaying a JavaScript function with a custom theme, belonging to the 'Functions' group, titled 'Greeting Function', highlighting lines 2, 4 to 6, showing line numbers, and starting line numbering from 1.

EXAMPLE 2

New-HTMLCodeBlock -Code "for ($i = 0; $i -lt 5; $i++) { Write-Host $i }" -Style 'powershell' -Group 'Loops' -Title 'For Loop Example' -ShowLineNumbers $false

Creates a new HTML code block displaying a PowerShell for loop without line numbers, belonging to the 'Loops' group, titled 'For Loop Example'.

Parameters

-Code String requiredposition: 0
Specifies the code content to be displayed in the code block.
-Group String optionalposition: 3
Specifies the group to which the code block belongs.
-Highlight String[] optionalposition: 5
Specifies specific lines to highlight in the code block.
-LineOffset String optionalposition: 7
Specifies the starting line number offset for line numbering.
-ShowLineNumbers Nullable`1 optionalposition: 6
Indicates whether line numbers should be displayed in the code block.
-Style String optionalposition: 1
Specifies the language style for syntax highlighting. Default is 'powershell'.
Possible values: assembly, asm, avrassembly, avrasm, c, cpp, c++, csharp, css, cython, cordpro, diff, docker, dockerfile, generic, standard, groovy, go, golang, html, ini, conf, java, js, javascript, jquery, mootools, ext.js, json, kotlin, less, lua, gfm, md, markdown, octave, matlab, nsis, php, powershell, prolog, py, python, raw, ruby, rust, scss, sass, shell, bash, sql, squirrel, swift, typescript, vhdl, visualbasic, vb, xml, yaml
-Theme String optionalposition: 2
Specifies the theme for the code block. Available themes include 'enlighter', 'beyond', 'classic', and more.
Possible values: enlighter, beyond, classic, godzilla, atomic, droide, minimal, eclipse, mowtwo, rowhammer, bootstrap4, dracula, monokai
-Title String optionalposition: 4
Specifies the title of the code block.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.