让 Windows(或 PowerShell)记录我在命令行中所做的一切?

Lan*_*sum 2 windows powershell

是否可以让 Windows 记录我键入的每个命令以及我在控制台上看到的输出?有时我发现我想看看我 2 小时前做了什么,以确保我正确输入了某个参数。

dan*_*gph 5

是的。您可以使用Start-TranscriptStop-Transcript

您让我想到将其放入我的 PowerShell 配置文件中,以便它自动启动。这是我想出的:

$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."
} 
Run Code Online (Sandbox Code Playgroud)