external help file | Locale | Module Name | ms.date | online version | schema | title |
---|---|---|---|---|---|---|
Microsoft.PowerShell.ConsoleHost.dll-help.xml |
en-US |
Microsoft.PowerShell.Host |
01/06/2025 |
2.0.0 |
Start-Transcript |
Creates a record of all or part of a PowerShell session to a text file.
Start-Transcript [[-Path] <String>] [-Append] [-Force] [-NoClobber] [-IncludeInvocationHeader] [-WhatIf]
[-Confirm] [<CommonParameters>]
Start-Transcript [[-LiteralPath] <String>] [-Append] [-Force] [-NoClobber] [-IncludeInvocationHeader] [-WhatIf]
[-Confirm] [<CommonParameters>]
Start-Transcript [[-OutputDirectory] <String>] [-Append] [-Force] [-NoClobber] [-IncludeInvocationHeader]
[-WhatIf] [-Confirm] [<CommonParameters>]
The Start-Transcript
cmdlet creates a record of all or part of a PowerShell session to a text
file. The transcript includes all command that the user types and all output that appears on the
console.
By default, Start-Transcript
stores the transcript in the following location using the default
name:
- Default location:
$HOME\Documents
- Default filename:
PowerShell_transcript.<computername>.<random>.<timestamp>.txt
Starting in Windows PowerShell 5.0, Start-Transcript
includes the hostname in the generated file
name of all transcripts. The filename also includes random characters in names to prevent potential
overwrites or duplication when you start two or more transcripts simultaneously. Including the
computer name is useful if you store your transcripts in a centralized location. The random
character string prevents guessing of the filename to gain unauthorized access to the file.
When using the Append parameter, if the target file doesn't have a Byte Order Mark (BOM)
Start-Transcript
defaults to ASCII
encoding in the target file. This behavior can result in
improper encoding of multibyte characters in the transcript.
Start-Transcript
This command starts a transcript in the default file location.
Start-Transcript -Path "C:\transcripts\transcript0.txt" -NoClobber
This command starts a transcript in the Transcript0.txt
file in C:\transcripts
. NoClobber
parameter prevents any existing files from being overwritten. If the Transcript0.txt
file already
exists, the command fails.
The following example creates a transcript file with a name unique enough to be stored on in a
shared location. The filename is constructed from the user's name, the hostname of the computer
running PowerShell, the version of PowerShell, and the date and time. The transcript is stored in
the \\Server01\Transcripts
file share.
$sharePath = '\\Server01\Transcripts'
$username = $Env:USERNAME
$hostname = hostname
$version = $PSVersionTable.PSVersion.ToString()
$datetime = Get-Date -F 'yyyyMMddHHmmss'
$filename = "Transcript-${username}-${hostname}-${version}-${datetime}.txt"
$Transcript = (Join-Path -Path $sharePath -ChildPath $filename).ToString()
Start-Transcript
The full path to the transcript file is stored in the $Transcript
preference variable. For more
information about the $Transcript
preference variable, see
about_Preference_Variables.
Indicates that this cmdlet adds the new transcript to the end of an existing file. Use the Path parameter to specify the file.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Allows the cmdlet to append the transcript to an existing read-only file. When used on a read-only file, the cmdlet changes the file permission to read-write. The cmdlet can't override security restrictions when this parameter is used.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Indicates that this cmdlet logs the time stamp when commands are run.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Specifies a location to the transcript file. Unlike the Path parameter, the value of the LiteralPath parameter is used exactly as it's typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks inform PowerShell not to interpret any characters as escape sequences.
Type: System.String
Parameter Sets: ByLiteralPath
Aliases: PSPath
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Indicates that this cmdlet doesn't overwrite an existing file. By default, if a transcript file
exists in the specified path, Start-Transcript
overwrites the file without warning.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: NoOverwrite
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Specifies a specific path and folder in which to save a transcript. PowerShell automatically assigns the transcript name.
Type: System.String
Parameter Sets: ByOutputDirectory
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Specifies a location to the transcript file. Enter a path to a .txt
file. Wildcards aren't
permitted. If any of the directories in the path don't exist, the command fails.
If you don't specify a path, Start-Transcript
uses the path in the value of the $Transcript
global variable. If you haven't created this variable, Start-Transcript
stores the transcripts in
the default location and filename.
Type: System.String
Parameter Sets: ByPath
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Prompts you for confirmation before running the cmdlet.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Shows what would happen if the cmdlet runs. The cmdlet isn't run.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
You can't pipe objects to this cmdlet.
This cmdlet returns a string containing a confirmation message and the path to the output file.
To stop a transcript, use the Stop-Transcript
cmdlet.
To record an entire session, add the Start-Transcript
command to your profile. For more
information, see about_Profiles.
Note
When you use Start-Transcript
, the default value of $InformationPreference
is changed to
Continue
. Output from Write-Information
is written to the console, but not to the transcript
file. If the $InformationPreference
is set to SilentlyContinue
, Information messages aren't
written to the console, but are written to the transcript file. This is fixed in PowerShell 6 and
higher.