Skip to content

Instantly share code, notes, and snippets.

@adbertram
Created April 22, 2018 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adbertram/af949da71dd1d774956ed221c4f98c88 to your computer and use it in GitHub Desktop.
Save adbertram/af949da71dd1d774956ed221c4f98c88 to your computer and use it in GitHub Desktop.
## Test file
Set-Content -Path 'foo.txt' -Value 'This is a test file'
## Run any command and pipe to my fictional function
Get-Content -Path C:\foo.txt -Raw | Copy-CommandToClipBoard
## When pasting from the clipboard, it would look like this
Get-Content -Path C:\foo.txt -Raw
This is a test file
@IISResetMe
Copy link

You mean like this?

function Copy-PipelineToClipboard {
    begin{
        $Command = $MyInvocation.Line -replace ('\|\s*{0}' -f $MyInvocation.InvocationName)
    }
    end{
        $Command,$input |Set-Clipboard
    }
}

Only works for one-line statements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment