Get scriptname in powershell

A short simple solution to get the filename of the script and replace the ending with .log instead of .exe or .ps1.
$LogFile = $MyInvocation.ScriptName -replace "^.*\\(.*)\..*$", '$1.log'

Note: In Powershell Studio, when compiling to executable, the code must read Hostinvocation instead of Myinvocation.

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.