Skip to content

Instantly share code, notes, and snippets.

@jrwarwick
Created August 25, 2016 17:12
Show Gist options
  • Save jrwarwick/242882376f1f9ed72488c070de1a189d to your computer and use it in GitHub Desktop.
Save jrwarwick/242882376f1f9ed72488c070de1a189d to your computer and use it in GitHub Desktop.
A quick, lean standard template for a PowerShell script that includes logging via start-transcript
## Standard informational header first.
##
## Configuration section next
$maxfoo = 10;
##
Start-Transcript -Path ".\$(([io.fileinfo]$MyInvocation.MyCommand.Definition).basename.Trim())_exec.log"
###### OR # "$($env:TEMP)\$(([io.fileinfo]$MyInvocation.MyCommand.Definition).basename.Trim())_exec.log"
###### OR # "$($env:LOGS)\$(([io.fileinfo]$MyInvocation.MyCommand.Definition).basename.Trim())_exec.log"
write-output "Ok now do all your stuff. "
write-output "This works well for powershell scheduled tasks, too; no need for redirection operators in the arguments box"
## Then put at the very end of the script:
Stop-Transcript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment