PS: Moving To Modules

less than 1 minute read

Description:

So I have re-ordered most my scripts into Modules now and set them to follow this guide.

To Resolve:

  1. Essentially, at the root of your module, you create two folders Public and Private.

  2. Under Public you place all your functions in one function per file that will get dot sourced when you import your function using Import-Module yourModuleName

  3. Under Private you place psm1 files that will not get called. Instead, in the public functions, you call the module in your private folder like so:

    1
    2
    3
    4
    
    If (-not (Test-path "$PSScriptRoot\..\Private\helpers.psm1"))
    {
       Import-Module $PSScriptRoot\..\Private\helpers.psm1"
    }
    
  4. See Part 2 to see my current setup.

Comments