How do I effectively copy and paste input and output in the Windows PowerShell?
11 Answers
- To select text in PowerShell with the mouse, just select it as usual.
- To copy the selected text to the clipboard you have to either hit Enter, or right-click.
- To paste into the PowerShell window, right click.
keyboard
- Paste: alt+[space], e, p
Note: In current versions of Windows 10, Ctrl+C, and Ctrl+V work as expected.
- 111,883
- 19
- 201
- 268
-
2This is what I was missing, thanks! To actually copy it is necessary to press Enter. – orschiro Mar 28 '12 at 17:13
-
1It is not necessary for me, but I have quickedit turned on in properties. – EBGreen Mar 28 '12 at 17:20
-
@orschiro: actually you don't need enter. I just tested it. You only need to highlight it and then right-click--> goes into clipboard. For pasting into powershell you only need to right click wherever you want. – Kamran Bigdely Jan 10 '14 at 16:23
-
right click to paste is not working on Windows 7 with PowerShell, seriously wtf – Alexander Mills Dec 02 '14 at 05:28
-
1ok, it works, but it won't paste multiline strings, that's BS – Alexander Mills Dec 02 '14 at 05:30
-
3you can also use the menu shortcut, `alt + [space] + e + p` menu->edit->paste – Val Mar 05 '15 at 10:49
-
I don't understand how right-click can be copy as well as paste. If I click in the window to select it, right-clicking copies whatever I've selected. If I click in it, then press enter to clear the selection, it copies what I've selected. I guess I have to click the title bar in order to focus on the window without selecting anything for copying. – sirdank May 31 '16 at 16:55
-
@SirDank It's "copy" when you have something highlighted, and "paste" when you don't. Also, pressing Enter doesn't replace the selected text with "enter" -- PS's window just doesn't work that way, you can't replace selected text by typing. – Ƭᴇcʜιᴇ007 May 31 '16 at 17:00
-
Doesn't Ctrl+C interrupt and halt an executing command? – mbomb007 Aug 12 '19 at 18:50
-
@mbomb007 Not if you have some text selected/highlighted when you hit Ctrl+C. – Ƭᴇcʜιᴇ007 Aug 15 '19 at 19:08
-
It does both for me, at least if I both have something running and something selected. – mbomb007 Aug 15 '19 at 21:27
-
2Nb! The menu shortcut will vary depending on the language version of Windows you have. On my Norwegian Windows install I must use `alt + [space], d, l` – Martin Jan 15 '20 at 21:39
-
`Shift + [Insert]` was much easier than `alt + [space] + e + p`, but now `Ctrl + c` works just fine. – caiohamamura Nov 15 '22 at 17:51
(Elaborating on the answer of Ƭᴇcʜιᴇ007 and Val)
Mouse
Select/Mark: Press left mouse button, drag, release.
Copy: Right-click.
Paste: With content in the clipboard, right-click.
Keyboard
Activate Mark: Alt + Space > e > k.
Select a Block: Navigate (arrow keys, Page-down, Page-up, End, Pos1) to the upper left corner of the block, press and hold Shift, navigate to the lower right corner, release Shift.
Copy: With a block selected, either hit Enter or Alt + Space > e > y.
Paste: With content in the clipboard, Alt + Space > e > p.
- 283
- 2
- 6
-
2+1 for the hint to "Activate Mark". I was searching combinations of Cursor and Caret but it always returned results for mouse cursor... – keremispirli Nov 10 '17 at 10:35
-
The *Active Mark* operation result in interesting behavior in pwsh 6.1 + PSReadLine 2.1.0. where the *Paste* operation, just insert the content at the current cursor position and not at the end of the last prompt. – not2qubit Oct 15 '20 at 10:39
Depends on which PowerShell you are using. With the newer PowerGUI Script Editor or with the PowerShell ISE (integrated scripting environment) cut/paste seems to work better:
- To cut drag the mouse across text to select, then ^C or right click to copy.
- To paste use ^V
With the older PowerShell:
- To cut drag the mouse across text to select, then enter to copy.
- You can sometimes hit ^C to copy but it does not seem to ALWAYS work.
- You can also drag to select then right click in the top window pane bar and select Edit | copy.
- To paste right click.
Good links for people learning PowerShell::
The best PowerShell tutorial I've found so far is here. It goes into quite a bit of description of the command line. Sadly some of the cool stuff in the original PowerShell appears to be broken in ISE, like ctrl-home for example, to delete to start of line.
Some differences between these two PowerShells is here.
- 4,089
- 8
- 24
- 37
- 1,160
- 12
- 23
-
2`Ctrl-V` also works in PowerShell on Windows 10 here (PS version 5.1.15063.296). – ComFreek Jun 02 '17 at 09:44
As of PowerShell Core 6, shortcut to copy and paste is Ctrl+Shift+C and Ctrl+Shift+V and is toggleable in the settings:
- 15,723
- 24
- 49
- 63
- 151
- 1
- 1
As of Windows 10, Ctrl + C works for copying the text & Ctrl + V works for paste. You can also select the data using Shift + Arrow(Left/Right).
The standard console can be used in Windows 10 — the PowerShell ISE is still available but not required for copy/paste support.
- 60,938
- 25
- 191
- 216
- 142
- 1
- 1
- 12
If you want to put the output of your command into the Clipboard, just use Set-Clipboard cmdlet as the final item in your pipeline, or its standard alias scb.
One caveat is that some commands return text (eg. Get-Content) and others produce collection of objects (eg. Get-ChildItem). If you get weird things in clipboard, insert Out-String before Set-Clipboard to convert everything to text:
gc .\myFile.txt | scb
ls c:\Windows | Out-String | scb
- 1,043
- 10
- 21
-
This works well in a PowerShell console. Something that works in both PowerShell and cmd.exe is `type .\myfile | clip` and `dir C:\Windows | clip`. – lit Mar 13 '23 at 20:13
Powershell functions like most terminal emulators (like PuTTY) - selecting text automatically copies it to your clipboard, and right-clicking pastes the content of your keyboard at your cursor.
- 379
- 1
- 9
-
Hello Rilgon, That was my first intuition but it does not work. Nothing gets copied to the clipboard. – orschiro Mar 28 '12 at 16:55
-
1That's strange, because I definitely just tried it myself just to make sure it was right, and it worked just fine. – Rilgon Arcsinh Mar 28 '12 at 16:55
-
Don't you need to hit enter to copy the contents to the clipboard in Powershell? – Bernard Chen Oct 10 '14 at 16:57
-
You just *select*, then `right-click` on the selection and it's in the clipboard. To paste, just `right-click` again. – not2qubit Oct 15 '20 at 10:41
To paste, you may use AutoHotkey script (this also affects all console windows):
#IfWinActive ahk_class ConsoleWindowClass
^V::
SendInput {Raw}%clipboard%
return
#IfWinActive
Found on http://www.howtogeek.com/howto/25590/how-to-enable-ctrlv-for-pasting-in-the-windows-command-prompt/.
- 377
- 4
- 19
Another way: highlight something, and control-mousedrag to copy it, in the Powershell ISE. Alt-hightlight also highlights rectangles.
- 575
- 5
- 6
Select text with the mouse or Shift+Arrows Ctrl+Shift+C to copy.
- 101
- 2
-
While we always appreciate new contributions, how is your answer really different from [this one](https://superuser.com/a/1184427/650163)? – Run5k Sep 10 '19 at 18:59
-
This is just to add a partial solution for those times you don't want to use the mouse. It only helps with pasting but you can press Alt+Space then e then p. The Alt+Space opens the PowerShell window's menu, the e opens the Edit sub-menu and the p does the actual pasting. Hardly convenient but it does save you from going to the mouse.
- 773
- 1
- 5
- 6
