3

I know about the Invoke-History command (alias r) to recall and execute a previous command, e.g. r 29 but is there a way to recall command 29 but not execute it, i.e. put it into the current line you can edit before running? A bit like pressing up-arrow multiple times? With a long history, it's a right pain to get back to edit & run and earlier command.

I know I can do something like this to recall the text of a command:

h 56 | fl

And then copy & paste but with long commands wrapping over a line, you have to copy & paste into an editor, join up the lines and then copy & paste back. Right faff!

munrobasher
  • 857
  • 5
  • 14
  • 30
  • This doesnt match the criteria for your answer, but DOSKEY.exe works in PowerShell. Maybe it will help a little. http://www.computerhope.com/doskeyhl.htm – Keltari Mar 07 '14 at 14:11

2 Answers2

2

Can not find a way of executing powershell within powershell but you can execute the powershell executable and pass the powershell command and it works. Might cause problems with scope depending what you are doing.

& powershell $(h 56).CommandLine
rob
  • 863
  • 12
  • 15
2

Not a pure Powershell solution, but you could pipe it into clip.exe and then paste it to the console. Still two steps but your line should wrap properly. If you are using XP you might need to copy clip.exe from a Server 2003 system.

(h 56).CommandLine | clip.exe
Spamwich
  • 301
  • 1
  • 5
  • Shouldn't that be `$(h 56)`. Also, could use `Set-Clipboard` instead of `clip.exe`. Good idea, though. – CJBS Jan 06 '18 at 07:30