How can I get the current PowerShell executing file? -
Note: PowerShell 1.0 - I would like to get the current current PowerShell file name. That is, if I start my session like this:
powershell.exe. Myfile.ps1 I string ". Myfile.ps1" (or something like that) Edit : "myfile.ps1" is better.
Any thoughts? The current answer is correct in most cases, but in some cases this will not give you the correct answer. If you use your script functions:
$ MyInvocation.MyCommand.Name returns the name of the function instead of the script name.
Function Test {$ MyInvocation.MyCommand.Name} You have been nominated to give " test ". To get the name of the script, the correct command always
$ MyInvocation.ScriptName gives the full path to this script that you are performing. If you only need a script file name in comparison to this code, then you should help:
partition-path $ MyInvocation.PSCommandPath -Leaf
Comments
Post a Comment