[powershell] Path of currently executing powershell script

How do I do this in PowerShell. In a batch file I would do: %~d0%~p0

This question is related to powershell

The answer is


From Get-ScriptDirectory to the Rescue blog entry ...

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

For PowerShell 3.0 users - following works for both modules and script files:

function Get-ScriptDirectory {
    Split-Path -parent $PSCommandPath
}

Split-Path $MyInvocation.MyCommand.Path -Parent

In powershell 2.0

split-path $pwd