Security Power Level: Advanced Chapter 17: PowerShell Security and Hardening
Logging and transcription
A transcript is a written record of a PowerShell session, and logging records what commands ran. These records help you review work later and understand what happened after an incident.
Lesson 3 of 4 in Chapter 17: PowerShell Security and Hardening. Previous step in this path: Constrained language mode. 3 learning objectives, 5 examples, and a knowledge check.
Start: what you will learn
A transcript is a written record of a PowerShell session, and logging records what commands ran. These records help you review work later and understand what happened after an incident.
Learning objectives
- Start and stop a transcript
- Explain what a transcript records
- Explain module logging and script block logging as policy concepts
Concept in simple words
What it is: A transcript is a text record of a PowerShell session, made with Start-Transcript and ended with Stop-Transcript. A session is one running copy of PowerShell. While the transcript is running, PowerShell writes the commands you type and the output that comes back into a text file, in order. When you stop the transcript, the record closes, and you can open that file later to review the whole session from start to finish.
What logging means in the wider sense: Logging is the wider idea of recording what happened, so an administrator can review it later. A transcript is a record you start yourself for one session. Module logging records commands from modules, which are packages of commands. Script block logging records blocks of script code as they run. An administrator enables these kinds of logging through policy, which is a managed rule for a computer or a group of computers. This lesson teaches the concepts, not the setup steps for those policies, because setup belongs to the administrator who owns the managed rule.
Why it works
Why this exists: Memory fades, and a busy session is hard to retell exactly. You may remember the result, but forget the exact command, the exact target, or the exact error that appeared halfway through. A written record keeps the commands and their output in order, so you can check your own work or trace a problem step by step. After an incident, which is an unexpected or harmful event, logs turn guessing into evidence you can read, compare, and share with a reviewer.
Think of it like this
Think of it like this: A transcript is like a notebook that writes itself while you work. You focus on the job, and the notebook keeps the commands and results. Later, you or a reviewer can open the notebook and see exactly what was typed and what came back. A notebook is only useful if you open it before the work starts, which is why the order matters: start the transcript first, then do the work, then stop the transcript, then review.
What PowerShell records behind the scenes in a transcript: The transcript records the commands in the order you ran them, plus the output those commands produced, including error messages that appeared during the session. It does not turn your session into a clean reusable script file. It keeps the messy truth of the session, including commands that failed, commands you corrected, and output that was longer than you expected. That messy truth is exactly what makes it useful for review, because a clean summary would hide the steps where a mistake happened.
How module logging and script block logging differ from a transcript: A transcript follows one session that you started by hand. Module logging and script block logging are policy enabled records that capture more detail across sessions, so an administrator can review command use and script blocks in event logs later. Module logging focuses on commands that come from modules. Script block logging focuses on blocks of script code as they run. You do not type a command each time to turn these on for one session, because they are managed rules. Your job as a learner is to understand what they record and why a reviewer would ask for them, not to set them up yourself.
How it works, step by step
How it works, step by step, in order: First, start a transcript before important work with Start-Transcript, and give it a file path where the record should be saved. Second, do your work as normal, and the transcript records commands and output. Third, end the record with Stop-Transcript when the work you want recorded is done. Fourth, open the transcript file and read it from top to bottom, checking each command and its output. Fifth, store the file where only the people who need it can read it, because a record of admin work deserves the same care as the work itself.
Worked example 1, starting a transcript: In Start-Transcript -Path .\session.txt, Start-Transcript starts the record, -Path names the file, and .\session.txt is the file in the current folder. Look for a message that says the transcript started and names the output file. That message is your proof that recording is on. If you change the path to a different folder or file name, the record goes to that new place, so use a clear name you can find later. If you leave out -Path, PowerShell chooses a default file, which is harder to find later, so naming the path is the clearer habit.
Worked example 2, work that gets recorded: In Get-Date, Get-Date is a simple read only command that shows the current date and time. After you start a transcript, a command like this is recorded along with its output, which is why it makes a good first test. Look for the Get-Date line in the transcript file later, followed by the date and time output. If you change Get-Date to a changing command, the transcript will still record it, which is why you should start the transcript before important changes, not after them. If you run Get-Date before starting the transcript, it will not appear in the record at all.
Worked example 3, stopping a transcript: In Stop-Transcript, Stop-Transcript closes the transcript started earlier, and it takes no file path, because it closes the record that is already running in this session. Look for a message that says the transcript stopped and names the output file. Run it when the work you want recorded is done, so the file holds a complete session. If you forget to stop it, the record keeps growing and later review gets harder, so make stopping part of your routine, just like saving a document.
Worked example 4, reading the transcript back: In Get-Content -Path .\session.txt, Get-Content reads a text file, -Path names the file, and .\session.txt is the transcript in the current folder. Look for the commands and outputs in order, from the start of the session to the stop message. Use this read back step to check your own work, not only to store the file and forget it. If you change the path to a different transcript file, you will read a different session, so check the file name before you draw a conclusion about what happened.
Worked example 5, adding to an existing transcript file: In Start-Transcript -Path .\session.txt -Append, Start-Transcript starts the record, -Path names the file, and -Append tells PowerShell to add to the existing file instead of replacing it. Look for a started message, then work as normal, and stop the transcript when you are done. Use -Append when you want to keep an earlier record in the same file and add a new session after it. If you leave out -Append and the file already exists, you risk losing the earlier record, so choose Append on purpose when keeping the old record matters.
What changes if you change one part: Change the file path and the record goes to a different file, so a reviewer looking in the old place will find nothing new. Change -Append to nothing and a new run may replace the old file content, which is a very different result from adding to it. Change Get-Content to a different file name and you read a different session. Change the order, so you start the transcript after the important work, and the key steps will be missing, even if every later step is recorded perfectly. Order and file name are not small details here, they decide whether the record is useful.
How to review a transcript well: Read from the top, not from the bottom, because order is the evidence. For each command, ask three questions. What did I intend to do. What did the command actually target. What did the output actually show. If the output shows an error, do not skip it, because the error may explain a later problem. If a command shows success, still check the next lines, because success output alone does not prove the right target changed. Write a short note about what you found, so the next reviewer does not have to repeat your whole reading.
Transcript records and event logs are different tools: A transcript is your session record, started by you, in a text file you named. An event log is a system record, written by Windows and by PowerShell logging policies, and read with tools such as Get-WinEvent. Use both when you audit a change. The transcript shows what you typed and saw. The event log shows what the system recorded about the same time. When both agree, your confidence grows. When they disagree, that disagreement is worth investigating, not ignoring.
When to use it
When to use it, and when not to: Use a transcript for important admin work, for a task you may need to explain later, and for any session where a clear record would help. Do not record secrets such as passwords in a transcript, because anything typed in a recorded session becomes part of the record. Do not leave transcript files where anyone can read them, because a record of admin work can reveal targets, names, and steps that should stay private. Do not treat a transcript as a backup of a script, because it is a record of one session, not a clean reusable file.
Edge cases that catch beginners: A transcript belongs to one session. Commands run in a different window will not appear in it, even if both windows are open at the same time. A transcript started after a problem will not contain the problem steps, so start early for important work. A very long session makes a very long file, so keep recorded sessions focused, and stop the transcript when the important work ends. A transcript file stored in a shared folder is shared, even if you only meant to share the folder for another reason, so check the folder permissions in your head before you choose the path.
Privacy and storage in plain terms: Treat a transcript file like a notebook that contains your working notes. Keep it where only the people who need it can open it. Keep it only as long as your team rule requires, and follow that rule instead of inventing your own. If a transcript contains a secret by accident, tell an administrator promptly and follow their advice about the file, instead of quietly deleting evidence that a reviewer may need. Care for the record is part of the skill, not an extra chore after it.
How to spot a mistake in your own thinking: If you think a transcript proves who did the work on a shared computer, pause, because a transcript records a session, and identity needs other evidence as well. If you think starting a transcript after the fact will recover lost steps, pause, because recording only starts when you start it. If you think a transcript file is a clean script you can run again, pause, because it contains prompts, outputs, and errors mixed with commands, and running it as a script would be a mess. Each pause protects the value of the record.
Worked examples
Read each example in order. Each one explains its parts, then shows what to look for in the output.
Syntax
Start-Transcript -Path <path>Example 1
Start-Transcript starts recording the session. The -Path parameter names the text file where the record is saved. Look for a started message that names the output file, which proves recording is on.
Start-Transcript -Path .\session.txtIllustrative output: Transcript started, output file is .\session.txt
Example 2
Get-Date is a simple read only command that shows the current date and time. After a transcript starts, this command and its output are recorded, so it makes a good first test that recording works.
Get-DateIllustrative output: 3 November 2026 10:00:00
Example 3
Stop-Transcript closes the transcript started earlier. It takes no file path, because it closes the record already running in this session. Run it when the work you want recorded is done, so the file holds a complete session.
Stop-TranscriptIllustrative output: Transcript stopped, output file is .\session.txt
Example 4
Get-Content reads a text file, and -Path names the transcript file. Look for commands and outputs in order, from the start of the session to the stop message, and use this read back step to check your work.
Get-Content -Path .\session.txtIllustrative output: Get-Date 3 November 2026 10:00:00
Example 5
Start-Transcript starts the record, -Path names the file, and -Append tells PowerShell to add to the existing file instead of replacing it. Use this form when you want to keep an earlier record in the same file.
Start-Transcript -Path .\session.txt -AppendIllustrative output: Transcript started, output file is .\session.txt
Nothing on this page executes PowerShell code. The outputs above are illustrative only.
Common mistakes and troubleshooting
Read these before you try the examples, so you can spot the same problems in your own work.
- Starting a transcript after the important work is already done, so the key steps are missing from the record.
- Saving transcripts in a shared folder without thinking about who can read them.
- Treating a transcript as a backup of a script, when it is a record of one session, not a clean reusable file.
- Reading a transcript while it is still recording, and expecting the final lines to be there before you stop it.
- Typing a secret in a recorded session, so the secret becomes part of the transcript file.
- Expecting commands from a different window to appear in a transcript, when a transcript belongs to only one session.
- Treating a transcript alone as proof of who did the work on a shared computer, when identity needs other evidence as well.
Knowledge check
Knowledge check
What does Start-Transcript do?
Pick one answer. Feedback appears right away, and you can try again.
Remember this and next step
Remember this: Start-Transcript starts the record, Stop-Transcript closes it, module logging and script block logging are policy enabled records that an administrator enables, and logs help you review work and learn from incidents. Start before the important work, read the record from top to bottom afterwards, store it safely, and never put a secret into a recorded session.
Next step: Safe scripting and auditing changes