How can I get the current PowerShell executing file?

前端 未结 10 1720
挽巷
挽巷 2020-12-07 15:04

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.ps         


        
10条回答
  •  情话喂你
    2020-12-07 15:55

    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.

提交回复
热议问题