Path of currently executing powershell script

Powershell

Powershell Problem Overview


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

Powershell Solutions


Solution 1 - Powershell

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

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

Solution 2 - Powershell

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

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

Solution 3 - Powershell

Split-Path $MyInvocation.MyCommand.Path -Parent

Solution 4 - Powershell

In powershell 2.0

split-path $pwd

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontempspaceView Question on Stackoverflow
Solution 1 - PowershellCodeMonkeyKingView Answer on Stackoverflow
Solution 2 - PowershellJP AliotoView Answer on Stackoverflow
Solution 3 - PowershellBill_StewartView Answer on Stackoverflow
Solution 4 - PowershellFeLocciView Answer on Stackoverflow