Set-Clipboard to paste a string that includes blank spaces

Topics: Developer Forum, User Forum
Dec 9, 2009 at 10:28 PM

Can anyone point me in the right direction where I could learn how to include a blank space in a string that I paste to the clipboard using {set-clipboard}?

To illustrate the problem, I can paste the word "now" to the windows clipboard, by opening a cmd prompt, and running the following code, using {set-clipboard}:

         C:\Users\marxp>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Sta "& {set-clipboard -text" "now"}

But, if I insert a blank space into the string "now" (i.e., "no w"), I get the following error, which I don't understand:

C:\Users\marxp>C:\Windows\System32\WindowsPowerShell\v1.\powershell.exe -Sta "& {set-clipboard -text" "no w"}

Set-Clipboard : A positional parameter cannot be found that accepts argument
At line:1 char:17
+ & {set-clipboard <<<< -text no w}
+ CategoryInfo : InvalidArgument: (:) [Set-Clipboard],
+ FullyQualifiedErrorId : PositionalParameterNotFound,Pscx.Commands.Clipbo



Dec 9, 2009 at 11:31 PM

Looks like a quoting problem to me.  Try this (worked on my box):


"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Sta "& {set-clipboard -text 'no w'}"

no w
Dec 11, 2009 at 10:54 PM
MikeShepard wrote:

Looks like a quoting problem to me.  Try this (worked on my box):


"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Sta "& {set-clipboard -text 'no w'}"

no w

 I love you.  (Don't tell my wife I said that.)

Where did you learn (and where can I learn) about those single quotes, i.e., (1) that le quotes were the right thing to put where you put them (around the 'no w'); (2) why single quote worked there, but double quotes wouldn't have done the job?

Thanks again.  Very much appreciated.


Dec 12, 2009 at 12:12 AM

For where to learn about them, try "get-help about_Quoting_Rules".


For why singles worked, where doubles didn't, it's just a matter of having quotes inside quotes.  It's much easier to put single quotes inside of double quotes (you don't have to double or escape them).



Mar 2, 2010 at 7:32 PM

Hello mike, I'm having kind of the same problem, see I have be copying items in the photoshop folder ( gradients, Actions, brushes etc) and the location is: %USERPROFILE%\AppData\Roaming\Adobe\Adobe Photoshop CS4\Presets\Actions . but it has a space and i get the error 'photoshop' because of the space.


if i copy to folders without space i have success.  Im using:  Copy-Item c:\Gradients\* C:\Users\MIA\AppData\Roaming\Adobe\Adobe Photoshop CS4\Presets\Gradients




Mar 2, 2010 at 7:53 PM
You just need to put quotes around the paths. This would work:

Copy-Item C:\Gradients\* "C:\Users\MIA\AppData\Roaming\Adobe\Adobe
Photoshop CS4\Presets\Gradients"
Mar 2, 2010 at 7:57 PM

Yes it worked, however, how abot the sourse folder like so:  Copy-Item D:\l3ny\Setm\PS Settings\Gradients\* "C:\Users\MIA\AppData\Roaming\Adobe\Adobe Photoshop CS4\Presets\Gradients"

i tried with no luck.

how will i put it on a scrip? a text with extention .ps1 ? thank you.

Mar 3, 2010 at 11:15 PM

You're getting rather far off topic, but ...

you need to quote BOTH paths, if they BOTH have spaces.

And yes, a script is just a text file full of commands, with a .ps1 extension.