# PoSh Module with script files as functions

**URL:** <https://forums.powershell.org/t/posh-module-with-script-files-as-functions/11303>\
**Category:** PowerShell Help\
**Created:** [September 12, 2018, 5:22am UTC](https://forums.powershell.org/t/posh-module-with-script-files-as-functions/11303 "2018-09-12T05:22:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kal3js](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@kal3js](https://forums.powershell.org/u/kal3js)\
**Post date:** [September 12, 2018, 5:22am UTC](https://forums.powershell.org/t/posh-module-with-script-files-as-functions/11303/1 "2018-09-12T05:22:25Z")

</div>

Hi all,

I have followed few guides on how to create a PowerShell module with multiple script files instead of just having one huge psm1 file. Since I placed the module in one of the default locations, I am not sure why the module is not auto-loaded. Please advise!

Here are the steps I followed:

1. C:\Users\Documents\WindowsPowerShell\Modules\myScripts

  
2. 

  
3. 

  
4. 

  
5. 

  
6. 

If I run the "Import-Module myScritps" command then all modules are imported, but that is not the goal, I would like the system to auto-import the modules every time I open PowerShell. Can you please advise what am I doing wrong?

Thank you!

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [September 12, 2018, 7:06am UTC](https://forums.powershell.org/t/posh-module-with-script-files-as-functions/11303/2 "2018-09-12T07:06:10Z")

</div>

First, you should check out [Plaster](https://kevinmarquette.github.io/2017-05-12-Powershell-Plaster-adventures-in/) to aid you in creating modules.

Second, if you have Powershell 3.0 or greater, then a [module will be automatically imported](https://stevenmurawski.com/2012/01/powershell-v3-auto-loading-of-modules/) if the module is located in one of the default paths listed in $env:PSModulePath. If I had a cmdlet named Get-Something and I referenced it, then Powershell should automatically import the module where Get-Something is contained. Another option is using a [Powershell profile](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-6)

---

<div class="post-metadata">

**Author:** ![ta11ow](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ta11ow/32/131_2.png) [@ta11ow](https://forums.powershell.org/u/ta11ow)\
**Post date:** [September 12, 2018, 7:10am UTC](https://forums.powershell.org/t/posh-module-with-script-files-as-functions/11303/3 "2018-09-12T07:10:49Z")

</div>

```
FunctionsToExport = '*'
```

This is your issue. Since the functions are not in the PSM1 directly, Powershell cannot determine what functions are available without executing the module; they will not auto import.

Never use a wildcard in your \*ToImport lines. Seriously, never. Even if you can make them work, they are _extraordinarily_ slow to work with, as the comments for the standard PSD1 template (that is generated from New-ModuleManifest) indicate.

Make a habit of updating your PSD1 every time you add another command.

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [September 12, 2018, 9:29am UTC](https://forums.powershell.org/t/posh-module-with-script-files-as-functions/11303/4 "2018-09-12T09:29:50Z")

</div>

Hi @Atis,

I request you to format the code when posting in the forum which makes other to easily understand your code, below link will help you.

- [How to format code in this forum](https://powershell.org/forums/topic/how-to-format-code-in-the-forums/)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/posh-module-with-script-files-as-functions/11303/5 "2024-05-16T20:34:24Z")

</div>

Closed on May 16, 2024, 8:34pm UTC


