I'm starting a PowerShell job with something like the following command:
start-job -filename my_script.ps1 -argumentlist ($v1, $v2, $v3)
This script, however needs to know where it's located, because it runs other commands based on their location relative to it. When run directly from the prompt, constructs such as these work:
join-path (split-path (& { $myinvocation.scriptname })) "relative path\filename"
join-path (split-path $myinvocation.mycommand.definition) "relative path\filename"
This doesn't work at all when started as a job as in the first example, however. How can I determine where I'm running from when I'm started as a job?