$MyInvocation in a runspace Thread

Multi tool use
A script (foo.ps1) creates a thread, and that thread creates more threads. Foo's thread is my control thread, and it creates one or more worker threads. The worker threads run a script block. The script block calls functions from a library-script. The library script has a configuration file.
The script block loads the library-script by dot-sourcing it.
When the script loads, the first thing it does is find its configuration file, which is in the script's directory. The code for that looks like...
My problem is $MyInvocation
doesn't appear to exist. As result, the library script can't find it's configuration file.
I'm running Powershell 5.1 on Windows 10. The control thread was made in a runspace. The worker threads are made in a runspace pool.
Does anyone know the rules around the automatic $MyInvocation
variable in runspace threads?
Create a file foo.ps1
and add the following to it:
Run it. You should see something like the following...
And, I think I just answered my own question.
I see variable in thread.
What are you doing differently?
Im not sure that $MyInvocation variable is supported in a background job
Can you pass the path as a parameter ?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.