How can I get the current PowerShell executing file?

前端 未结 10 1728
挽巷
挽巷 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:45

    If you are looking for the current directory in which the script is being executed, you can try this one:

    $fullPathIncFileName = $MyInvocation.MyCommand.Definition
    $currentScriptName = $MyInvocation.MyCommand.Name
    $currentExecutingPath = $fullPathIncFileName.Replace($currentScriptName, "")
    
    Write-Host $currentExecutingPath
    

提交回复
热议问题