How do i use Get-clipboard output in a powershell script?

Aqua

i'm trying to use text that is inside the clipboard inside a powershell script. So what the purpose for the script, i want to be able to copy a file directory and then run the script so it uses the copied directory as a automatic destination. So my idea was to do something like this:

Copy-Item C:\Users\gif.gif -Destination "Copied Directory"

I'm very new to powershell scripting, so an explenation of what is going on would be nice but not needed. I origionlly thought that this could work but nope XD, this should have been a simple project but yeah it wasn't meant to be easy.

Copy-Item C:\Users\J.J\Documents\TouchPortal/Make_30fps_gif.bat -Destination | Get-Clipboard

Would love to get some help with this, and thank you in advance!

Steven

In PowerShell core including versions 6 & 7 Get-Clipboard only works with text. If you use it after copying a folder it will return null.

In PowerShell 5.1 (Windows PowerShell) you can use the -Format parameter with Get-Clipboard

See mklement0's answer for a better description and example using -Format.

If you need to use the newer versions, you can use the shift + context menu choice > Copy as Path to get the folder's string path on to the clipboard, but that will quote the path. The quoted path will then be rejected by Copy-Item.

However, you could quickly replace the quotes like below.

Copy-Item 'C:\temp\BaseFile.txt' -Destination (Get-Clipboard).Replace('"',"")

Caution though, this seems hazardous and I wouldn't advise it. I use Get-Clipboard all the time to get data into a console session and can attest that it's too easy to make mistakes. The clipboard is so transient and it's use so ubiquitous that even if you make this work it's bound to burn you at some point.

Maybe you can elaborate on what you're trying to do and why. Then we can brainstorm the best approach.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I use clipboard in GTK?

How do I use a certain output as a variable (in PowerShell)?

How do I use a script's output in an Ant Conditional

How do I use a CloudFormation output value in a script with Ansible

How do I get PowerShell script to delete users on other computers?

How do I pipe terminal standard output (stdout) to the clipboard?

Powershell script - How can I get this script to only output values that match a certain string

How do I get StreamWriter in PowerShell to create a file and use it?

How do I use Clipboard.js dynamically with background color?

How do I properly use Clipboard in a console application?

How do I get the clipboard to work in CentOS inside VirtualBox on Windows?

How do you get powershell script output in the deployment log for a vNext Release Template?

How do I use a variable in an SQL script passed in from a powershell script

How do I implement output variables in powershell?

How do I get windows registry property values using a PowerShell script run through a .Net PowerShell object?

How should I do to get the script output from the GraalJS script engine encoded correctly?

Love to get the output of powershell script in a variable to use in a batch file

How to run node js script from powershell script and use the output of node js script in powershell script?

How can I use a shebang in a PowerShell script?

How do I read the output of commands in a script

How do I save the output of a script to a file?

How do I write the output of this loop to a script

How do I reformat the output of a BASH script?

How do i use a script in another script?

How do I run a PowerShell script as a service?

How I can do this powershell script better?

How do I count the points in a PowerShell script?

In Powershell, how do I use Compare-Object based on one property but output all properties?

How do I use Get-EventLog to get the same result of Get-WinEvent in PowerShell?