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

Add-HTMLScript

Module PSWriteHTML

Adds JavaScript content to the HTML body.

Syntax

Add-HTMLScript [-AddComments] [[-Content] <String[]>] [[-FilePath] <String[]>] [[-Link] <String[]>] [[-Placement] <Inline|Header|Footer>] [[-ReplaceData] <IDictionary>] [[-Resource] <IDictionary>] [[-ResourceComment] <String>] [-SkipTags] [<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

This function adds JavaScript content to the HTML body by including JavaScript code from files, strings, or links. It allows customization of the placement of JavaScript content within the HTML document.

Examples

Authored help example

EXAMPLE 1

Add-HTMLScript -Placement 'Header' -Resource 'MyScript' -ResourceComment 'Script for functionality X' -Link 'https://example.com/script.js'
Adds an external JavaScript file 'script.js' to the header of the HTML document with a specified comment.

EXAMPLE 2

Add-HTMLScript -Placement 'Footer' -Resource 'CustomScript' -ResourceComment 'Custom script for feature Y' -Content 'function myFunction() { // code here }'
Adds custom JavaScript content to the footer of the HTML document with a specified comment.

EXAMPLE 3

Add-HTMLScript -Placement 'Inline' -Resource 'InlineScript' -ResourceComment 'Inline script for page Z' -FilePath 'C:\Scripts\inline.js' -ReplaceData @{ 'placeholder' = 'replacement' }
Adds JavaScript code from a file 'inline.js' to be included inline in the HTML document with specified replacements.

Parameters

-AddComments SwitchParameter optional
Indicates whether to add comments around the JavaScript content. By default, comments are not added.
-Content String[] optionalposition: 4
Specifies an array of JavaScript content as strings to be included.
-FilePath String[] optionalposition: 5
Specifies an array of file paths containing JavaScript code to be included.
Specifies an array of URLs to external JavaScript files to be included.
-Placement String optionalposition: 0
Specifies where the JavaScript content should be placed in the HTML document. Valid values are 'Inline', 'Header', or 'Footer'. Default is 'Header'.
Possible values: Inline, Header, Footer
-ReplaceData IDictionary optionalposition: 6
Specifies a dictionary of key-value pairs to replace in the JavaScript code.
-Resource IDictionary optionalposition: 1
Specifies the resource containing the JavaScript content.
-ResourceComment String optionalposition: 2
Specifies a comment to be included with the JavaScript content.
-SkipTags SwitchParameter optional
Indicates whether to skip adding script tags around the JavaScript content. By default, script tags are added.

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.