February 10, 2020 at 1:18 am #202661ParticipantTopics: 2Replies: 3Points: 17Rank: Member
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.
February 10, 2020 at 3:54 am #202667Senior ModeratorTopics: 8Replies: 1169Points: 4,100Rank: Community Hero
Don’t know whether I understood your problem properly, but you might want to look at $PSScriptRoot automatic variable.
February 10, 2020 at 10:36 am #202700ParticipantTopics: 2Replies: 3Points: 17Rank: Member
Thanks @kvprasoon, I will looks at this. To clarify (hopefully), lets try this:
Original Script. say located on a users desktop (
#This will do something, and reference a function in another file...
$variable = function1
Then we have
#This is function1, which references function2.ps1. Both files should be in the same folder. . .\function2.ps1 $check = function2 do something... return
Function2 will not be loaded as the location is set to the path of the original script.
February 10, 2020 at 3:35 pm #202730
- You must be logged in to reply to this topic.