当前正在执行的powershell脚本的路径

65 powershell

我如何在PowerShell中执行此操作.在批处理文件中,我会这样做:%~d0%~p0

Cod*_*ing 42

对于PowerShell 3.0用户 - 以下适用于模块和脚本文件:

function Get-ScriptDirectory {
    Split-Path -parent $PSCommandPath
}
Run Code Online (Sandbox Code Playgroud)


JP *_*oto 36

Get-ScriptDirectory到Rescue博客条目......

function Get-ScriptDirectory
{
  $Invocation = (Get-Variable MyInvocation -Scope 1).Value
  Split-Path $Invocation.MyCommand.Path
}
Run Code Online (Sandbox Code Playgroud)


Bil*_*art 13

Split-Path $MyInvocation.MyCommand.Path -Parent
Run Code Online (Sandbox Code Playgroud)