A -Passthru option for the Set-Clipboard command.
PS C:\Users\Drew> "The quick brown fox jumps over the lazy dog." | Set-Clipboard -Passthru
The quick brown fox jumps over the lazy dog.
PS C:\Users\Drew> Get-Clipboard
The quick brown fox jumps over the lazy dog.
I got this mocked up and working.
PS C:\> 'This is a test of the PassThru parameter' | Set-Clipboard -PassThru
This is a test of the PassThru parameter
PS C:\> 'This is a test of the PassThru parameter', 'and multiple values' | Set-Clipboard -PassThru
This is a test of the PassThru parameter
and multiple values
The PR seems to have some discussion on what is the expected behavior of -Passthru, basically, is it simply returning back what was put in. If so, if you pipe an array, should you get back an array or the single concatenated object that now exists in the clipboard? Alternatively, does -Passthru return the result of what you're setting which means if -Append is used, then it should be the entire contents of the clipboard? I think what would help to answer these questions is how users intend to use this switch and some examples of real world usage.
The PR seems to have some discussion on what is the expected behavior of
-Passthru, basically, is it simply returning back what was put in. If so, if you pipe an array, should you get back an array or the single concatenated object that now exists in the clipboard? Alternatively, does-Passthrureturn the result of what you're setting which means if-Appendis used, then it should be the entire contents of the clipboard? I think what would help to answer these questions is how users intend to use this switch and some examples of real world usage.
When I pipe an array into Set-Clipboard, my clipboard (according to Get-Clipboard) contains an array, not a string. (I am only on 5.1 however, I'm not sure if this has changed.)
I think using -Passthru with -Append should return the entire clipboard, that feels intuitive to me, and consistent with other cmdlets eg the Active Directory suite, where using Set-ADUser with -Passthru returns the ADUser object, rather than the particular properties I've set.
I'll put this here from the PR:
Set-Clipboard -PassThru without the -Append switch parameter and Get-Clipboard will always return the same data. This is the correct example:
$result = 'hello', 'world' | Set-Clipboard -PassThru
$result
hello
world
Get-Clipboard
hello
world
The scenario I'm talking about is when the clipboard already has data and the -Append switch is used to add data. In that scenario should be behavior be to output the entire clipboard or just the the passed data?
$result = 'hello' | Set-Clipboard -PassThru
$result
hello
$result = 'world' | Set-Clipboard -Append -PassThru
$result
hello
world
Get-Clipboard
hello
world
$result = 'hello' | Set-Clipboard -PassThru
$result
hello
$result = 'world' | Set-Clipboard -Append -PassThru
$result
world
Get-Clipboard
hello
world
The reason I ask is because, in all the other cmdlets with a -PassThru parameter, only the passed data is sent down the pipeline, not everything. In this example, lets replace Set-Clipboard -PassThru -Append with Add-Content -PassThru. The user is adding world to the file and specified -PassThru. I don't think any user would expect that the entire contents of the file would be output during this command. And as we expect when we run the commands we don't get hello and world but, just world. That is because the user may want to use world in other cmdlets. Hopefully, this example shows the similarities between the clipboard and files when it comes to -PassThru -Append logic.
C:\> Set-Content -Path c:\temp\content.txt -Value 'hello'
C:\> 'world' | Add-Content -Path C:\temp\content.txt -PassThru
world
Most helpful comment
I got this mocked up and working.