Werbung

Herkunft

Kurzinformation

Copies the currently selected text in the current file with colorization

Syntax

<# .Synopsis Copies the currently selected text in the current file with colorization .Description Copies the currently selected text in the current file with colorization. This allows for a user to paste colorized scripts into Word or Outlook .Example Copy-Colored #> param() if (-not $psise.CurrentFile) { Write-Error 'You must have an open script file' return } function Colorize { # colorize a script file or function param([string]$Text, [int]$Start = -1, [int]$End = -1) trap { break } $rtb = New-Object Windows.Forms.RichTextBox $rtb.Font = New-Object Drawing.Font $psise.Options.FontName, $psise.Options.FontSize $rtb.Text = $Text # Now parse the text and report any errors... $parse_errs = $null $tokens = [system.management.automation.psparser]::Tokenize($rtb.Text, [ref] $parse_errs) if ($parse_errs) { $parse_errs return } # iterate over the tokens an set the colors appropriately... foreach ($t in $tokens) { $rtb.Select($t.start, $t.length) $color = $psise.Options.TokenColors[$t.Type] if ($color) { $rtb.selectioncolor = [drawing.color]::FromArgb($color.A, $color.R, $color.G, $color.B) } } if ($start -eq -1 -and $end -eq -1) { $rtb.select(0,$rtb.Text.Length) } else { $rtb.select($start, $end) } $rtb.Copy() } $selectedRunspace = $psise.CurrentFile $selectedEditor=$selectedRunspace.Editor $FullText = $selectedEditor.Text -replace '\r\n', "`n" if (-not $selectedEditor.SelectedText) { $TextToColor = ($selectedEditor.Text -replace '\r\n', "`n") } else { $TextToColor = ($selectedEditor.SelectedText -replace '\r\n', "`n") } Colorize $FullText $FullText.IndexOf(($TextToColor -replace '\r\n', "`n")) $TextToColor.Length

Beschreibung

Copies the currently selected text in the current file with colorization.This allows for a user to paste colorized scripts into Word or Outlook

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