6

It is easy to view the command history of powershell, but sometimes, one might forget to record some important output of the commands, and wish to have a look back into what was on the screen?

Is the history of outputs automatically saved somewhere?

2 Answers 2

11

By default, PowerShell records history of commands, but not their output.

You can request PowerShell to record screen output into a file. Use Start-Transcript and Stop-Transcript for this.

Example

Start-Transcript

'do stuff here'
Get-Service X*
'do some more stuff here'

Stop-Transcript

If you want PowerShell to automatically record all your stuff every time, you can add Start-Transcript in your PowerShell profile (use $PROFILE system variable to find path to your profile script, then add Start-Transcript into it)

By default, a new text file is created every time you start transcript. If you want to keep adding output into the same file, then Start-Transcript -Path C:\ExistingTranscript.txt -Append

Sign up to request clarification or add additional context in comments.

1 Comment

Of course, from a security standpoint this should be highly discouraged, as passwords and other secrets could end up sitting in some plaintext file on the drive (and then maybe even synced to the cloud and other machines) ...
0

To automatically run the Start-Transcript to save outputs:

The path and file represented by the $PROFILE system variable are not created on my computer. To create this path and file, run the following command.

if (!(Test-Path -Path $PROFILE)) {
  New-Item -ItemType File -Path $PROFILE -Force
}

Then run notepad $PROFILE.
Then paste the Start-Transcript into the file (For me is ...\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1)

1 Comment

See my comment above - this is probably unwise: stackoverflow.com/questions/71099275/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.