Reputation: 169
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?
Upvotes: 6
Views: 5109
Reputation: 168
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)
Upvotes: 0
Reputation: 432
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
Upvotes: 11