The path to the currently running powershell script

How to do it in PowerShell. In a batch file, I would do:% ~ D0% ~ p0

+56
powershell
Jul 25 '09 at 10:00
source share
4 answers

For PowerShell 3.0 users - after working for both modules and script files:

 function Get-ScriptDirectory { Split-Path -parent $PSCommandPath } 
+36
Mar 14 '13 at 6:00
source share

From an entry in Get-ScriptDirectory to save ...

 function Get-ScriptDirectory { $Invocation = (Get-Variable MyInvocation -Scope 1).Value Split-Path $Invocation.MyCommand.Path } 
+35
Jul 25 '09 at 22:09
source share
 Split-Path $MyInvocation.MyCommand.Path -Parent 
+10
Feb 27 '13 at 17:32
source share

In powershell 2.0

split-path $ pwd

-13
07 Oct '13 at 21:47
source share



All Articles