Dot-source script files in a module vs. importing via the manifest

This topic contains 3 replies, has 3 voices, and was last updated by  Joel Newton 2 years, 1 month ago.

  • Author
  • #34640

    Joel Newton

    I have a rather large custom module that I've made available on github. I've had a few requests to extract the functions into individual .PS1 files that are then loaded by the .PSM1 file. Is this something that can be handled via telling the manifest to include/import all .PS1 files located in specific folders, or will I need to put the logic for dot-sourcing the PS1 files into the .PSM1 file?

  • #34641

    Dave Wyatt

    I tend to dot-source. Particularly for the scenario you describe (just load everything in the folder), it's easier to just use Get-ChildItem and a foreach loop.

  • #34650

    Don Jones

    You could also create a manifest for the module, and have it import all of them when the module is loaded. But, as Dave implies, you have to explicitly list them all – there's no so much a wildcard option that way.

  • #34663

    Joel Newton

    Thanks, guys. So until manifests are able to accept wildcards, sounds like I'll be sticking with dot-sourcing. Cheers.

You must be logged in to reply to this topic.