February 2019
Intermediate to advanced
626 pages
15h 51m
English
HTML defines a number of special characters; for example, a literal ampersand (&) in HTML must be written as &.
ConvertTo-Html will handle the conversion of special characters in input objects, but it will not work with special characters in raw HTML that are added using the Body, Head, PreContent, or PostContent parameters.
The Sytem.Web.HttpUtility class includes methods that are able to convert strings containing such characters.
Before System.Web.HttpUtility can be used, the assembly must be added:
Add-Type -AssemblyName System.Web
The HtmlEncode static method will take a string and replace any reserved characters with HTML code. For example, the following snippet will replace > with >:
PS>'<h1>{0}</h1>' ...Read now
Unlock full access