4

In what way could I log my previously entered commands in visual studio code? For instance when I press up key I can up through all my previous commands, I would like to log these to a file if possible.

Where are they stored locally? Could I log it with something like node?

DGRFDSGN
  • 575
  • 1
  • 8
  • 20
  • You want to log only cmdlet history or would [Start-Transcript](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-6) do the trick? – Robert Dyjas Jun 18 '18 at 07:54
  • I would like to log the history, have looked at Start/Stop transcript, good call though! :) – DGRFDSGN Jun 20 '18 at 07:02

2 Answers2

6

I've actually solved this myself thanks to the help of @bruce-payette and @robdy for pointing me in new directions. Logging all commands, also from previous sessions, can be done from PowerShell itself. Enter this command in PowerShell to recieve the path to a file where PowerShell saves the history accessible by using the up key:

(Get-PSReadlineOption).HistorySavePath

This will output something like this:

C:\Users\[username]\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt

Open this file to see all saved commands from previous sessions!

Mihai Chelaru
  • 7,614
  • 14
  • 45
  • 51
DGRFDSGN
  • 575
  • 1
  • 8
  • 20
  • also note that `$PROFILE` is in a different path for the Pwsh extension. If you place your profile in `$PROFILE.CurrentUserAllHosts` it will share it for both – ninMonkey Oct 18 '22 at 23:26
2

The cmdlet Get-History will give you the history of the commands you've run. You can save this to a file by doing

Get-History | Out-File myhistory.txt
Bruce Payette
  • 2,511
  • 10
  • 8
  • Yeah that output's my history from this session perfect, thanks @bruce-payette! Do you know if there is a way to get the cmds from older sessions? I.E. i keep pressing up and see older commands, but the output file contains 1 entry from the current sesh.. – DGRFDSGN Jun 20 '18 at 06:58