Thursday, April 8, 2010

Change to folder that PowerShell script is located

To change to the folder or directory that the executing PowerShell script is located:

pushd (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)

Alternatively:

$scriptFolder = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

Note that $PSScriptRoot is preferable for PowerShell 3.0.

0 comments:

Post a Comment