Set-clipboard multiple times

Hi
I’m converting an old batch script to powershell.
The batch script was using

c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile -c "Set-Clipboard -Value '%data3%'" 
c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile -c "Set-Clipboard -Value '%data2%'" 
c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile -c "Set-Clipboard -Value '%data1%'"

The goal here is to have the 3 datas in the clipboard history so that the user can pick whatever he needs with “windows+v”.
However when using the same method in my powershell, I end up having only data1 in the clipboard, it doesn’t add data to the clipboard history.
Any idea why?
And no, I don’t want all the data in the same clipboard box.
Any idea how to do it ?

thx

Hey there! Welcome!

Each time you run Set-Clipboard it will overwrite the previous clipboard. I’m not sure how you had this working before in the batch script, but as it’s written now that’s the reason why. Even with clipboard history turned on i think ctrl v selects the most recent clipboard, and to view the clipboard history you’d hit windows key v.

I think perhaps what you are missing is logic handling. I’d think ideally based on some criterion, your end user using the code would be selecting something, and that would entail what you put on the clipboard. If that’s the case, you have a some approaches that you could use to ‘capture’ user input but it depends on the workflow.

You could use Read-Host and present a user with options, and based on their input, Set the proper thing to the clipboard.

You could use a function potentially to take parameters, and based on that, set the clipboard.

Not sure we know enough about the whole process and there’s others out there, but may be helpful to better understand the workflow start to finish before I suggest anything else :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.