Finding Out a Scripts Parent Folder

by Nov 25, 2008

If you need to find helper files that are stored in the same folder, you may want to know where a given script is stored. The automatic variable $MyInvocation can provide this information. The following commands tell you the script name and the parent folder name. They only work inside a PowerShell script and you cannot use them interactively.

$MyInvocation.MyCommand.Definition
Split-Path -parent $MyInvocation.MyCommand.Definition