Not sure when you might need to get data from Clipboard. But I thought it might be useful in some cases which I might not think about.
So, below is the piece of code which can be used.
Getting Data from Clipboard:
Below code will look if the Clipboard contains a text data and if this is so, it would display. You may store it into variable and do whatever you like.
Setting Data into Clipboard:
Use below piece of code to set a value to the Clipboard. To confirm if value is set or not, please use above section.
Clearing Data from Clipboard:
Below code can be used to clear data available in clipboard.
I hope this will help you. Please comment here if you have any thoughts about it.
So, below is the piece of code which can be used.
Getting Data from Clipboard:
Below code will look if the Clipboard contains a text data and if this is so, it would display. You may store it into variable and do whatever you like.
#--Statement to Get Text Data from Clipboard --# if ( [System.Windows.Forms.Clipboard]::GetText() -ne "" ) { [System.Windows.Forms.Clipboard]::GetText() else { Write-Output "Clpboard does not contain Text data" }
Setting Data into Clipboard:
Use below piece of code to set a value to the Clipboard. To confirm if value is set or not, please use above section.
#--Statement to Set item into Clipboard --# $Data_to_Set="Som DT" if ($Data_to_Set -ne "" ) { [System.Windows.Forms.Clipboard]::SetText($Data_to_Set) }
Clearing Data from Clipboard:
Below code can be used to clear data available in clipboard.
#--Statement to clear the data from clipboard --# [System.Windows.Forms.Clipboard]::Clear()
I hope this will help you. Please comment here if you have any thoughts about it.
Thank you for sharing this helped me out!
ReplyDeleteReally wish there was a cmdlet for managing the clip board built in.
Just what I was looking for, thanks.
ReplyDeleteWhen I save the Getting Data from Clipboard: above as a ps1 file, it does nothing. It shows no output. What I want to do is copy the clipboard (a url)and send it to vlc media player. This is what a functional command line looks like in a .bat file: "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "https://playerservices.streamtheworld.com/api/livestream-redirect/KINK.mp3" but I don't know how to replace the url in that command line with the current clipboard contents.
ReplyDelete