tags:

views:

254

answers:

2

Note: PowerShell 1.0
I'd like to get the current executing PowerShell file name. That is, if I start my session like this:

powershell.exe .\myfile.ps1

I'd like to get the string ".\myfile.ps1" (or something like that). EDIT: "myfile.ps1" is preferable.
Any ideas?

+4  A: 

Try the following

$path =  $MyInvocation.MyCommand.Definition

This may not give you the actual path typed in but it will give you a valid path to the file.

JaredPar
+5  A: 

If you only want the filename (not the full path) use this:

$ScriptName = $MyInvocation.MyCommand.Name
Keith Hill