How to get the modules root directory?

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of OCram85 OCram85 1 month ago.

  • Author
    Posts
  • #66874
    Profile photo of OCram85
    OCram85
    Participant

    Hi guys,

    I'm currently working on several module functions.
    Now I need to get the modules root directory. Do I need to work with `$PSScriptRoot`, `$PSCmdlet` or `$MyInvocation`? – I thought there is an automatic variable ?

  • #66876
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    Hi OCram85,

    $MyInvocation.MyCommand.Module.ModuleBase should work.

    • #66877
      Profile photo of OCram85
      OCram85
      Participant

      Ahh nice... That`s what I was searching for 🙂

  • #66879
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    Try this:

    $ENV:PSModulePath -split ';'
    • #67024
      Profile photo of OCram85
      OCram85
      Participant

      Well, this would return a list of all available module paths. But I really need the current root directory of the module I'm currently in. So @daniel-krebs idea seems to be the easiest way. (At least for me ^^).

      But thanks anyway!

You must be logged in to reply to this topic.