2021-01-18
Powershell: Transcript (Log)
A transcript logs all action of a Powershell session to a text file; good for documenting and archiving.
With Start-Transcript, you begin a record of the current Powershell session.
After quitting the Powershell session, the recording stops, but you can also stop the recording manually by running Stop-Transcript.
You can also modify your Powershell profile to start recording automatically every time when you start a Powershell session by adding something similar like this to it:
$LogFolder = "$Home\Documents\WindowsPowerShell\Logs"
Get-Item -Path "$LogFolder\Log-*.txt" | Where {$_.LastWriteTime -lt ((Get-Date).AddDays(-90))} | Remove-Item
Start-Transcript -NoClobber -Append -Path $LogFolder\Log-$(Get-Date -Format yyyy-MM-dd).txt
# ...
# Stop-Transcript
A few words abou the parameters:
- -Path specifies another destination and filename.
- -OutputDirectory specifies the path to a folder(!) in which the transcript is being saved. In this case, the name of the file will automatically be chosen by Powershell.
- -NoClobber indicates that this cmdlet will not overwrite an existing file.
- -Append indicates that the new transcript will be added to the end of an existing file with the specified name.
- -IncludeInvocationHeader indicates that this cmdlet logs the time stamp when commands are run.
Categories: How To
Development (85)
DevLog (19)
Hardware (3)
How To (74)
Mini-Reviews (58)
News & Announcements (20)
On Software (12)
Projects (26)
DevLog (19)
Hardware (3)
How To (74)
Mini-Reviews (58)
News & Announcements (20)
On Software (12)
Projects (26)
ANSI Escape Code (1)
·
Bluetooth (1)
·
C++ (12)
·
Citrix (1)
·
Clang (1)
·
CMake (12)
·
DE (8)
·
Doxygen (1)
·
EN (193)
·
Excel (1)
·
Filezilla (1)
·
Firefox (1)
·
Git (3)
·
GNU Compiler Collection (1)
·
Hotkey (1)
·
Hugo (2)
·
JSON (2)
·
Lua (3)
·
Mercurial (4)
·
MoOde (1)
·
MTP (2)
·
Notepad++ (3)
·
Pico-8 (1)
·
Powershell (26)
·
PuTTY (1)
·
Python (5)
·
QEMU (1)
·
Qt (11)
·
RandFill (15)
·
Raspberry Pi (1)
·
RegEx (1)
·
Remi (2)
·
RSS (2)
·
SCP (1)
·
SDL (2)
·
SIMInfo (7)
·
Site (1)
·
SSH (2)
·
Trackball (1)
·
Visual Studio (11)
·
Win32 (2)
·
Windows (27)
·
WordPress (3)
·
WPD (3)
·
WPDLib (2)
·
WPF (1)
·
WxWidgets (1)
·
XAML (1)
·
XML (1)
·
YouTube (1)