Powershell: Get Clipboard Content to use with your script

I wrote a little script for a Reddit user on /r/techsupport that allows him to download a youtube Video with copying the URL and just starting the script. (Download with youtube-dl https://github.com/rg3/youtube-dl/)

The Clipboard part was the most fun and I guess some people can use it.

I basically create a WinForm which I won’t show and use the System.Windows.Forms.Textbox „paste()“ function to get the text:

<code>add-type -assemblyname system.windows.forms
$form = new-object System.Windows.Forms.TextBox
$form.multiline = $true
$form.paste()
$form.Text</code>

 

Your Clipboard content will be in $form.Text