How to get the modules root directory?

Welcome Forums General PowerShell Q&A How to get the modules root directory?

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
1 year, 9 months ago.

  • Author
    Posts
  • #66874

    Participant
    Points: 22
    Rank: Member

    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

    Moderator
    Points: 24
    Team Member
    Rank: Member

    Hi OCram85,

    $MyInvocation.MyCommand.Module.ModuleBase should work.

  • #66879

    Participant
    Points: 269
    Helping Hand
    Rank: Contributor

    Try this:

    $ENV:PSModulePath -split ';'
    • #67024

      Participant
      Points: 22
      Rank: Member

      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!

The topic ‘How to get the modules root directory?’ is closed to new replies.