Created
July 31, 2020 08:47
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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