Multiple dot course functions and relative paths

Hey all,

I am dot sourcing a function from an original script which in itself would dot course another function. I am looking for a way to determine the file location of the first dot sourced function so I can create a relative link to the second dot sourced location (relative to the first). The first/second function file should always be in the same directory.

When running a `Get-Location` within the first dot source file, it seems as if the original script location is referenced. It may be the the calling function isn’t always in the same location, indeed the dot sourced function might not be in the same place, but both function files should be in the same folder.

I have worked around this by dot sourcing both file in the original script, but this might not always be known.

Don’t know whether I understood your problem properly, but you might want to look at $PSScriptRoot automatic variable.

Thanks @kvprasoon, I will looks at this. To clarify (hopefully), lets try this:

Original Script. say located on a users desktop (C:\users\me\desktop\script.ps1)

#This will do something, and reference a function in another file...</code>
<code>. .C:\somepathtoscrits\function1.ps1</code>
<code>$variable = function1

Then we have function1.ps1

#This is function1, which references function2.ps1. Both files should be in the same folder.
. .\function2.ps1
$check = function2
do something...

Function2 will not be loaded as the location is set to the path of the original script.