Is there any way to get the path to the script that imported the module from this module?
The script module that I am writing is designed to load settings from files regarding import script. I plan to reuse the module for a number of projects, so I would prefer that the module cannot make any assumptions about where to import it from.
It's nice to have, it would be great that the module can be as explicit as possible. If all else fails, I can simply transfer the call to my location.
Unfortunately, everything I tried so far returns the path to the module (and not the one that imported it). Here is a simple demo:
Test-RelativeModule.ps1 , saved to: c: \ test \
import-module "$PSScriptRoot\mod\Test.psm1"
Test.psm1 , saved to: c: \ test \ mod \
write-host "`$PSScriptRoot: $PSScriptRoot"
write-host "Split Invoation: $(Split-Path $MyInvocation.MyCommand.Path)"
write-host "Resolve Path: $((resolve-path '.\').path)"