Evotec

Project

PSWriteHTML

PSWriteHTML is an open-source PowerShell project with packages, release history, and working documentation.

Stars 995
Forks 114
Open issues 69
PowerShell Gallery downloads 7,436,513
Release v1.41.0
Language: PowerShell Updated: 2026-04-11

API Reference

Function

Add-HTMLScript

Aliases: Add-JavaScript, Add-JS, New-JavaScript
Namespace PSWriteHTML
Aliases
Add-JavaScript Add-JS New-JavaScript

Adds JavaScript content to the HTML body.

Remarks

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.
        

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.

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

Parameters

AddComments SwitchParameter optionalposition: namedpipeline: False
Indicates whether to add comments around the JavaScript content. By default, comments are not added.
Content String[] optionalposition: 4pipeline: False
Specifies an array of JavaScript content as strings to be included.
FilePath String[] optionalposition: 5pipeline: False
Specifies an array of file paths containing JavaScript code to be included.
Link String[] optionalposition: 3pipeline: False
Specifies an array of URLs to external JavaScript files to be included.
Placement String optionalposition: 0pipeline: Falsevalues: 3
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: 6pipeline: False
Specifies a dictionary of key-value pairs to replace in the JavaScript code.
Resource IDictionary optionalposition: 1pipeline: False
Specifies the resource containing the JavaScript content.
ResourceComment String optionalposition: 2pipeline: False
Specifies a comment to be included with the JavaScript content.
SkipTags SwitchParameter optionalposition: namedpipeline: False
Indicates whether to skip adding script tags around the JavaScript content. By default, script tags are added.