Werbung

Herkunft

Kurzinformation

Writes Windows PowerShell as colorized HTML

Syntax

<# .Synopsis Writes Windows PowerShell as colorized HTML .Description Outputs a Windows PowerShell script as colorized HTML. The script is wrapped in
 tags with  tags defining color regions.
    .Example
        Write-ColoredHTML {Get-Process}
    #>
    param(
        # The Text to colorize
        [Parameter(Mandatory=$true)]
        [String]$Text,
        # The starting within the string to colorize
        [Int]$Start = -1,
        # the end within the string to colorize
        [Int]$End = -1)
trap { break } 
    #
    # Now parse the text and report any errors...
    #
    $parse_errs = $null
    $tokens = [Management.Automation.PsParser]::Tokenize($text,
        [ref] $parse_errs)
 
    if ($parse_errs) {
        $parse_errs
        return
    }
    $stringBuilder = New-Object Text.StringBuilder
    $null = $stringBuilder.Append("
")
    # iterate over the tokens an set the colors appropriately...
    $lastToken = $null
    foreach ($t in $tokens)
    {
        if ($lastToken) {
            $spaces = " " * ($t.Start - ($lastToken.Start + $lastToken.Length))
            $null = $stringBuilder.Append($spaces)
        }
        if ($t.Type -eq "NewLine") {
            $null = $stringBuilder.Append("            
")
        } else {
            $chunk = $text.SubString($t.start, $t.length)
            $color = $psise.Options.TokenColors[$t.Type]            
            $redChunk = "{0:x2}" -f $color.R
            $greenChunk = "{0:x2}" -f $color.G
            $blueChunk = "{0:x2}" -f $color.B
            $colorChunk = "#$redChunk$greenChunk$blueChunk"
            $null = $stringBuilder.Append("$chunk")                    
        }                       
        $lastToken = $t
    }
    $null = $stringBuilder.Append("
") $stringBuilder.ToString()

Beschreibung

Outputs a Windows PowerShell script as colorized HTML.The script is wrapped in
 tags with  tags defining color regions.
   
  
  
     

Links

Liste aller Commandlets Mehr über die Windows PowerShell

Bücher zur PowerShell

Buchcover Windows PowerShell 5.0 - Das Praxishandbuch (1. Auflage 2016/5. Auflage Gesamtreihe) Windows PowerShell 5.0 - Das Praxishandbuch (1. Auflage 2016/5. Auflage Gesamtreihe)
Autoren: Dr. Holger Schwichtenberg
erschienen 2016, 996 Seiten, 49,99 €
ISBN: 3446446435
Bestellung: Amazon.de oder im Buchhandel über ISBN 3446446435

Schulungen/Seminare

Offene Seminare zur PowerShell
In-House-Seminare zur PowerShell