Skip to content

Instantly share code, notes, and snippets.

@OlafD
Created July 31, 2020 08:47
Show Gist options
  • Save OlafD/0d55001bcb7113026465c43cf8edbb08 to your computer and use it in GitHub Desktop.
Save OlafD/0d55001bcb7113026465c43cf8edbb08 to your computer and use it in GitHub Desktop.
Sample for storing a transcript of a PowerShell script execution to a file. The path for the transcript file is a mandatory parameter in the script.
param (
[Parameter(Mandatory=$true)]
[string]$TranscriptPath
)
$scriptName = $MyInvocation.MyCommand.Name.Substring(0, $MyInvocation.MyCommand.Name.IndexOf("."))
$transcriptExtension = Get-Date -Format yyyyMMdd-HHmmss
$transcriptFile = "$TranscriptPath\$scriptName" + "_Transcript_$transcriptExtension.txt"
Start-Transcript -Path $transcriptFile
Write-Host "Output of the script execution"
Stop-Transcript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment