I have a few unusual, relatively complex/large PowerShell scripts where it outputs colorized text via Write-Host. I want to copy the entire text output to the Windows clipboard WITHOUT losing tab characters (with windows Control-C, clipboard copy) or alternative. If I highlight all the text after the script runs in a PowerShell.exe console Window, then, press control-C (to copy to the Windows clipboard) the tab characters are converted to spaces.
If I try to use Set-Clipboard cmdlet below to pipe entire output of my script, there are too many components in my script (mainly Write-Host lines) which aren't compatible with further PS pipeline processing; so, Set-Clipboard below is completely ignored (only displaying output to to local host console).
PS: I've also tried Start-Transcript\Stop-Transcript.. However, that doesnt capture tabs either. It converts tabs to spaces.
I was hoping someone had a clever, quick way to clipboard capture the text I get from cmdlets that need write-host THAT ALSO CAPTURE `t tab characters.
invoke-myscript -Devicename "WindowsPC" | Set-Clipboard
function Set-Clipboard {
param(
    ## The input to send to the clipboard
    [Parameter(ValueFromPipeline = $true)]
    [object[]] $InputObject
)
begin
{
    Set-StrictMode -Version Latest
    $objectsToProcess = @()
}
process
{
    ## Collect everything sent to the script either through
    ## pipeline input, or direct input.
    $objectsToProcess += $inputObject
}
end
{
    ## Launch a new instance of PowerShell in STA mode.
    ## This lets us interact with the Windows clipboard.
    $objectsToProcess | PowerShell -NoProfile -STA -Command {
        Add-Type -Assembly PresentationCore
        ## Convert the input objects to a string representation
        $clipText = ($input | Out-String -Stream) -join "`r`n"
        ## And finally set the clipboard text
        [Windows.Clipboard]::SetText($clipText)
    }
}