How do I do this in PowerShell. In a batch file I would do: %~d0%~p0
4 Answers
From Get-ScriptDirectory to the Rescue blog entry ...
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
2 Comments
dan-gph
See also the answer at the duplicate: stackoverflow.com/a/6985381/60620
Wolf
link in answer => 404
Split-Path $MyInvocation.MyCommand.Path -Parent
2 Comments
alex
What's
$MyInvocation?Dan Atkinson
@alex
$MyInvocation is an automatic variable created by PowerShell. From the docs (linked): Contains information about the current command, such as the name, parameters, parameter values, and information about how the command was started, called, or invoked, such as the name of the script that called the current command.In powershell 2.0
split-path $pwd
1 Comment
majkinetor
Wroking directory is not the same as scripts directory.