Created
August 25, 2016 17:12
-
-
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
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
| ## 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