Path of currently executing powershell script
PowershellPowershell 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