Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example creating a unique transcript filename #10438

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions reference/5.1/Microsoft.PowerShell.Host/Start-Transcript.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ This command starts a transcript in the `Transcript0.txt` file in `C:\transcript
**NoClobber** parameter is used, the command prevents any existing files from being overwritten. If
the `Transcript0.txt` file already exists, the command fails.

### Example 3: Start a transcript file with a unique name and store it on a file share

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.

```powershell
$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
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](../Microsoft.PowerShell.Core/About/about_Preference_Variables.md#transcript).

## PARAMETERS

### -Append
Expand All @@ -94,7 +116,7 @@ Accept wildcard characters: False
### -Force

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 cannot override security
file, the cmdlet changes the file permission to read-write. The cmdlet can't override security
restrictions when this parameter is used.

```yaml
Expand Down Expand Up @@ -128,9 +150,9 @@ Accept wildcard characters: False
### -LiteralPath

Specifies a location to the transcript file. Unlike the **Path** parameter, the value of the
**LiteralPath** parameter is used exactly as it is 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.
**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.

```yaml
Type: System.String
Expand All @@ -146,7 +168,7 @@ Accept wildcard characters: False

### -NoClobber

Indicates that this cmdlet does not overwrite an existing file. By default, if a transcript file
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.

```yaml
Expand Down Expand Up @@ -180,14 +202,14 @@ Accept wildcard characters: False

### -Path

Specifies a location to the transcript file. Enter a path to a `.txt` file. Wildcards are not
Specifies a location to the transcript file. Enter a path to a `.txt` file. Wildcards aren't
permitted.

If you do not specify a path, `Start-Transcript` uses the path in the value of the `$Transcript`
global variable. If you have not created this variable, `Start-Transcript` stores the transcripts in
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 `$HOME\My Documents directory as \PowerShell_transcript.<time-stamp>.txt` files.

If any of the directories in the path do not exist, the command fails.
If any of the directories in the path don't exist, the command fails.

```yaml
Type: System.String
Expand Down Expand Up @@ -220,7 +242,7 @@ Accept wildcard characters: False
### -WhatIf

Shows what would happen if the cmdlet runs.
The cmdlet is not run.
The cmdlet isn't run.

```yaml
Type: System.Management.Automation.SwitchParameter
Expand All @@ -238,7 +260,8 @@ 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](https://go.microsoft.com/fwlink/?LinkID=113216).
-WarningAction, and -WarningVariable. For more information, see
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

Expand All @@ -262,3 +285,5 @@ information, see [about_Profiles](../Microsoft.PowerShell.Core/About/about_Profi
## RELATED LINKS

[Stop-Transcript](Stop-Transcript.md)

[about_Preference_Variables](../Microsoft.PowerShell.Core/About/about_Preference_Variables.md#transcript)
49 changes: 37 additions & 12 deletions reference/7.2/Microsoft.PowerShell.Host/Start-Transcript.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.ConsoleHost.dll-Help.xml
Locale: en-US
Module Name: Microsoft.PowerShell.Host
ms.date: 12/12/2022
ms.date: 09/20/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-7.2&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Start-Transcript
Expand Down Expand Up @@ -71,6 +71,28 @@ This command starts a transcript in the `Transcript0.txt` file in `C:\transcript
**NoClobber** parameter is used, the command prevents any existing files from being overwritten. If
the `Transcript0.txt` file already exists, the command fails.

### Example 3: Start a transcript file with a unique name and store it on a file share

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.

```powershell
$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
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](../Microsoft.PowerShell.Core/About/about_Preference_Variables.md#transcript).

## PARAMETERS

### -Append
Expand All @@ -93,7 +115,7 @@ Accept wildcard characters: False
### -Force

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 cannot override security
file, the cmdlet changes the file permission to read-write. The cmdlet can't override security
restrictions when this parameter is used.

```yaml
Expand Down Expand Up @@ -127,9 +149,9 @@ Accept wildcard characters: False
### -LiteralPath

Specifies a location to the transcript file. Unlike the **Path** parameter, the value of the
**LiteralPath** parameter is used exactly as it is 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.
**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.

```yaml
Type: System.String
Expand All @@ -145,7 +167,7 @@ Accept wildcard characters: False

### -NoClobber

Indicates that this cmdlet does not overwrite an existing file. By default, if a transcript file
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.

```yaml
Expand Down Expand Up @@ -179,14 +201,14 @@ Accept wildcard characters: False

### -Path

Specifies a location to the transcript file. Enter a path to a `.txt` file. Wildcards are not
Specifies a location to the transcript file. Enter a path to a `.txt` file. Wildcards aren't
permitted.

If you do not specify a path, `Start-Transcript` uses the path in the value of the `$Transcript`
global variable. If you have not created this variable, `Start-Transcript` stores the transcripts in
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 `$HOME\My Documents directory as \PowerShell_transcript.<time-stamp>.txt` files.

If any of the directories in the path do not exist, the command fails.
If any of the directories in the path don't exist, the command fails.

```yaml
Type: System.String
Expand Down Expand Up @@ -236,7 +258,7 @@ Accept wildcard characters: False
### -WhatIf

Shows what would happen if the cmdlet runs.
The cmdlet is not run.
The cmdlet isn't run.

```yaml
Type: System.Management.Automation.SwitchParameter
Expand All @@ -254,7 +276,8 @@ 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](https://go.microsoft.com/fwlink/?LinkID=113216).
-WarningAction, and -WarningVariable. For more information, see
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

Expand All @@ -278,3 +301,5 @@ information, see [about_Profiles](../Microsoft.PowerShell.Core/About/about_Profi
## RELATED LINKS

[Stop-Transcript](Stop-Transcript.md)

[about_Preference_Variables](../Microsoft.PowerShell.Core/About/about_Preference_Variables.md#transcript)
49 changes: 37 additions & 12 deletions reference/7.3/Microsoft.PowerShell.Host/Start-Transcript.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.ConsoleHost.dll-Help.xml
Locale: en-US
Module Name: Microsoft.PowerShell.Host
ms.date: 12/12/2022
ms.date: 09/20/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-7.3&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Start-Transcript
Expand Down Expand Up @@ -71,6 +71,28 @@ This command starts a transcript in the `Transcript0.txt` file in `C:\transcript
**NoClobber** parameter is used, the command prevents any existing files from being overwritten. If
the `Transcript0.txt` file already exists, the command fails.

### Example 3: Start a transcript file with a unique name and store it on a file share

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.

```powershell
$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
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](../Microsoft.PowerShell.Core/About/about_Preference_Variables.md#transcript).

## PARAMETERS

### -Append
Expand All @@ -93,7 +115,7 @@ Accept wildcard characters: False
### -Force

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 cannot override security
file, the cmdlet changes the file permission to read-write. The cmdlet can't override security
restrictions when this parameter is used.

```yaml
Expand Down Expand Up @@ -127,9 +149,9 @@ Accept wildcard characters: False
### -LiteralPath

Specifies a location to the transcript file. Unlike the **Path** parameter, the value of the
**LiteralPath** parameter is used exactly as it is 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.
**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.

```yaml
Type: System.String
Expand All @@ -145,7 +167,7 @@ Accept wildcard characters: False

### -NoClobber

Indicates that this cmdlet does not overwrite an existing file. By default, if a transcript file
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.

```yaml
Expand Down Expand Up @@ -179,14 +201,14 @@ Accept wildcard characters: False

### -Path

Specifies a location to the transcript file. Enter a path to a `.txt` file. Wildcards are not
Specifies a location to the transcript file. Enter a path to a `.txt` file. Wildcards aren't
permitted.

If you do not specify a path, `Start-Transcript` uses the path in the value of the `$Transcript`
global variable. If you have not created this variable, `Start-Transcript` stores the transcripts in
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 `$HOME\My Documents directory as \PowerShell_transcript.<time-stamp>.txt` files.

If any of the directories in the path do not exist, the command fails.
If any of the directories in the path don't exist, the command fails.

```yaml
Type: System.String
Expand Down Expand Up @@ -236,7 +258,7 @@ Accept wildcard characters: False
### -WhatIf

Shows what would happen if the cmdlet runs.
The cmdlet is not run.
The cmdlet isn't run.

```yaml
Type: System.Management.Automation.SwitchParameter
Expand All @@ -254,7 +276,8 @@ 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](https://go.microsoft.com/fwlink/?LinkID=113216).
-WarningAction, and -WarningVariable. For more information, see
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

Expand All @@ -278,3 +301,5 @@ information, see [about_Profiles](../Microsoft.PowerShell.Core/About/about_Profi
## RELATED LINKS

[Stop-Transcript](Stop-Transcript.md)

[about_Preference_Variables](../Microsoft.PowerShell.Core/About/about_Preference_Variables.md#transcript)
Loading