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!

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
  • 952
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
  • 320