2

Is it possible to have windows log every command I type & the output I see on the console? Sometimes I find that I want to see what I did 2 hours ago just to be sure I typed a certain parameter in correctly.

2
  • Is it just me or is this comment almost always at the top of SU?
    – Jon
    Feb 6, 2014 at 4:18
  • It does seem to be pretty popular, although I can't imagine it's that popular.
    – Lanissum
    Apr 12, 2016 at 5:24

3 Answers 3

5

Yes. You can use Start-Transcript and Stop-Transcript.

You have given me the idea to put that in my PowerShell profile so that it starts automatically. This is what I have come up with:

$transcriptDir = Join-Path ([Environment]::GetFolderPath("MyDocuments")) PowerShellTranscripts
if (-not (Test-Path $transcriptDir))
{
    New-Item -Type Directory $transcriptDir
}
$dateStamp = Get-Date -Format ((Get-culture).DateTimeFormat.SortableDateTimePattern -replace ':','.')
try 
{
    Start-Transcript "$transcriptDir\Transcript.$dateStamp.txt"
}
catch [System.Management.Automation.PSNotSupportedException]
{
    # ISE doesn't allow transcripts.
    Write-Host "No transcript. Not supported in this host."
} 
1
  • Thank you dangph, this would be sufficient for my purposes and it is simple to accomplish.
    – Lanissum
    Feb 10, 2014 at 22:59
0

Note: I prepared this answer, and then realized you are probably asking specifically about commands executed within PowerShell. Rather than erase my effort, I am going to post in case it help someone looking at doing the same thing within DOS. Doing a bit of reading, it looks like @dangph has probably given the correct answer for PowerShell.


To log commands to a file:

doskey /history >> commands.log to append your command history to a log.

This page explains in details, but in a nutshell you can pipe your commands to a file of choice before closing your DOS emulator. You wouldn't have to do this until after you're done (not sure if buffer comes into play with large volume of commands)

To log command output to a file:

You would probably want something like...

dir >> a.txt | type a.txt. As mentioned in that answer, you are writing command output to a file and then printing the contents of the file, but I think it fits the bill and would be automatic if you used it with every command. If you tweak a little, I think you could probably modify to also write the command as well as the output.

Perhaps someone can improve or suggest a more user-friendly solution to do both (append command and results) at once, as statements are executed.

0

What is wrong with (History -count 1000).CommandLine as a native powershell solution.

To log everything at the command line (for security purposes) I'd use

HKEY: HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Audit\
RegEntry: ProcessCreationIncludeCmdLine_Enabled 
Value: 1 (DWORD)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .