2009-07-25 13 views
46

Wie mache ich das in PowerShell? In einer Batch-Datei würde ich tun: % ~ d0% ~ p0Pfad zur Ausführung des Powershell-Skripts

+0

Dup: http://stackoverflow.com/questions/801967/how-can-i-find-the-source-path-of-an-executing-script –

+2

Durch die Weg, können Sie das auf% ~ dp0 –

Antwort

30

Von Get-ScriptDirectory to the Rescue Blogeintrag ...

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

verkürzen Siehe auch die Antwort auf das Duplikat: http://StackOverflow.com/a/6985381/60620 –

9
split-path $SCRIPT:MyInvocation.MyCommand.Path -parent 

Bill

30

Für PowerShell 3.0 Benutzer - folgende Arbeiten für beide Module und Skriptdateien:

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

In Powershell 2.0

Split-Path $ PWD

+3

Wroking-Verzeichnis ist nicht das gleiche wie Skripte Verzeichnis. – majkinetor

Verwandte Themen