powershell - Get the path of the importing script from within a module? -
Is there a way to obtain the path to that script that imports the module from that module?
The script module I am writing to load settings from files relative to the import script. I am planning to reuse the module for many projects, so I like if the module can not make any assumption about where it is being imported from.
It's a good one, this great module will be rooted as possible, if everything fails, then I might have a caller pass.
Unfortunately, I've tried everything the path of the module (this is not imported) Here's a simple demonstration:
Test-Relative module.P1 , it has been archived: c: \ test \ Test.psm1 strong>, stored: c: \ test \ mod \ Return 'c: \ test' from within module # without any assumptions about
# returns 'c: \ test \ mod' write -host "$ PSScriptRoot: $ PSScriptRoot" $ return 'c: \ test \ mod' # $ MyInvocation.MyCommand.Path's value is 'c: \ test \ mod \ test.psm1' Type - Host "Split Invoicing: $ (Split-path $ MyInvocation.MyCommand.Path) "#Which path console is currently written "Resolve Path: $ ((Hull-path '. \'. Path), which gives any route on" # "What I'm seeing
< Code> Write-Host "PSScriptRoot: $ ($ MyInvocation.PSScriptRoot) of My Invitation"
Comments
Post a Comment