< Back

ConvertTo-NSEnhancedHTMLFragment

Mon Jan 13, 2020 9:01 pm

NAME ConvertTo-NSEnhancedHTMLFragment



SYNOPSIS

Creates an HTML fragment (much like ConvertTo-HTML with the -Fragment switch

that includes CSS class names for table rows, CSS class and ID names for the

table, and wraps the table in a <DIV> tag that has a CSS class and ID name.





SYNTAX

ConvertTo-NSEnhancedHTMLFragment [-InputObject] <Object[]> [[-EvenRowCssClass] <String>] [[-OddRowCssClass]

<String>] [[-TableCssID] <String>] [[-DivCssID] <String>] [[-DivCssClass] <String>] [[-TableCssClass] <String>]

[[-As] <String>] [[-Properties] <Object[]>] [[-PreContent] <String>] [-MakeHiddenSection] [-MakeTableDynamic]

[[-PostContent] <String>] [<CommonParameters>]





DESCRIPTION





PARAMETERS

-InputObject <Object[]>

The object to be converted to HTML. You cannot select properties using this

command; precede this command with Select-Object if you need a subset of

the objects' properties.



Required? true

Position? 1

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-EvenRowCssClass <String>

The CSS class name applied to even-numbered <TR> tags. Optional, but if you

use it you must also include -OddRowCssClass.



Required? false

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-OddRowCssClass <String>

The CSS class name applied to odd-numbered <TR> tags. Optional, but if you

use it you must also include -EvenRowCssClass.



Required? false

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



-TableCssID <String>

Optional. The CSS ID name applied to the <TABLE> tag.



Required? false

Position? 4

Default value

Accept pipeline input? false

Accept wildcard characters? false



-DivCssID <String>

Optional. The CSS ID name applied to the <DIV> tag which is wrapped around the table.



Required? false

Position? 5

Default value

Accept pipeline input? false

Accept wildcard characters? false



-DivCssClass <String>

Optional. The CSS class name to apply to the wrapping <DIV> tag.



Required? false

Position? 6

Default value

Accept pipeline input? false

Accept wildcard characters? false



-TableCssClass <String>

Optional. The CSS class name to apply to the <TABLE> tag.



Required? false

Position? 7

Default value

Accept pipeline input? false

Accept wildcard characters? false



-As <String>

Must be 'List' or 'Table.' Defaults to Table. Actually produces an HTML

table either way; with Table the output is a grid-like display. With

List the output is a two-column table with properties in the left column

and values in the right column.



Required? false

Position? 8

Default value Table

Accept pipeline input? false

Accept wildcard characters? false



-Properties <Object[]>

A comma-separated list of properties to include in the HTML fragment.

This can be * (which is the default) to include all properties of the

piped-in object(s). In addition to property names, you can also use a

hashtable similar to that used with Select-Object. For example:





Get-Process | ConvertTo-NSEnhancedHTMLFragment -As Table `

-Properties Name,ID,@{n='VM';

e={$_.VM};

css={if ($_.VM -gt 100) { 'red' }

else { 'green' }}}





This will create table cell rows with the calculated CSS class names.

E.g., for a process with a VM greater than 100, you'd get:





<TD class="red">475858</TD>



You can use this feature to specify a CSS class for each table cell

based upon the contents of that cell. Valid keys in the hashtable are:





n, name, l, or label: The table column header

e or expression: The table cell contents

css or csslcass: The CSS class name to apply to the <TD> tag



Another example:





@{n='Free(MB)';

e={$_.FreeSpace / 1MB -as [int]};

css={ if ($_.FreeSpace -lt 100) { 'red' } else { 'blue' }}



This example creates a column titled "Free(MB)". It will contain

the input object's FreeSpace property, divided by 1MB and cast

as a whole number (integer). If the value is less than 100, the

table cell will be given the CSS class "red." If not, the table

cell will be given the CSS class "blue." The supplied cascading

style sheet must define ".red" and ".blue" for those to have any

effect.



Required? false

Position? 9

Default value *

Accept pipeline input? false

Accept wildcard characters? false



-PreContent <String>

Raw HTML content to be placed before the wrapping <DIV> tag.

For example:





-PreContent "<h2>Section A</h2>"



Required? false

Position? 10

Default value

Accept pipeline input? false

Accept wildcard characters? false



-MakeHiddenSection [<SwitchParameter>]

Used in conjunction with -PreContent. Adding this switch, which

needs no value, turns your -PreContent into clickable report

section header. The section will be hidden by default, and clicking

the header will toggle its visibility.





When using this parameter, consider adding a symbol to your -PreContent

that helps indicate this is an expandable section. For example:





-PreContent '<h2>&diams; My Section</h2>'





If you use -MakeHiddenSection, you MUST provide -PreContent also, or

the hidden section will not have a section header and will not be

visible.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-MakeTableDynamic [<SwitchParameter>]

When using "-As Table", makes the table dynamic. Will be ignored

if you use "-As List". Dynamic tables are sortable, searchable, and

are paginated.





You should not use even/odd styling with tables that are made

dynamic. Dynamic tables automatically have their own even/odd

styling. You can apply CSS classes named ".odd" and ".even" in

your CSS to style the even/odd in a dynamic table.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-PostContent <String>

Raw HTML content to be placed after the wrapping <DIV> tag.

For example:





-PostContent "<hr />"



Required? false

Position? 11

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Consider adding the following to your CSS when using dynamic tables

(replace the * with .):





*paginate_enabled_next, .paginate_enabled_previous {

cursor:pointer;

border:1px solid #222222;

background-color:#dddddd;

padding:2px;

margin:4px;

border-radius:2px;

}

*paginate_disabled_previous, .paginate_disabled_next {

color:#666666;

cursor:pointer;

background-color:#dddddd;

padding:2px;

margin:4px;

border-radius:2px;

}

*dataTables_info { margin-bottom:4px; }





This applies appropriate coloring to the next/previous buttons,

and applies a small amount of space after the dynamic table.





If you choose to make sections hidden (meaning they can be shown

and hidden by clicking on the section header), consider adding

the following to your CSS (replace the * with .):





*sectionheader { cursor:pointer; }

*sectionheader:hover { color:red; }





This will apply a hover-over color, and change the cursor icon,

to help visually indicate that the section can be toggled.



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$fragment = Get-WmiObject -Class Win32_LogicalDisk |



Select-Object -Property PSComputerName,DeviceID,FreeSpace,Size |

ConvertTo-HTMLFragment -EvenRowClass 'even' `

-OddRowClass 'odd' `

-PreContent '<h2>Disk Report</h2>' `

-MakeHiddenSection `

-MakeTableDynamic





You will usually save fragments to a variable, so that multiple fragments

(each in its own variable) can be passed to ConvertTo-NSEnhancedHTML.











RELATED LINKS