I have a powershell file called main.ps1 and it is in a project file structured as such:
APP > Tools > main.ps1
I'm wondering if there is a more efficient way to getting the path of the App directory. I'm using the following function:
$myFile = ($MyInvocation.MyCommand.Path)
function Root {
$parentPath = Split-Path -parent $myFile
$root = Split-Path -parent $parentPath
$base = Split-Path -parent $root
return $root, $base
}
$Root, $Base = Root
When the script is run MyInvocation saves the path of main.ps1 to the $myFile variable. Knowing this folder is always 2 folders deep in the App directory I use the -parent twice in a row and that gives me the path of the App folder.
Is there a more efficient way?