# Multi-File Modules with Classes

**URL:** <https://forums.powershell.org/t/multi-file-modules-with-classes/13111>\
**Category:** PowerShell Help\
**Created:** [September 9, 2019, 12:44pm UTC](https://forums.powershell.org/t/multi-file-modules-with-classes/13111 "2019-09-09T12:44:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cantoriscomputing](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/cantoriscomputing/32/179_2.png) [@cantoriscomputing](https://forums.powershell.org/u/cantoriscomputing)\
**Post date:** [September 9, 2019, 12:44pm UTC](https://forums.powershell.org/t/multi-file-modules-with-classes/13111/1 "2019-09-09T12:44:33Z")

</div>

Hi!

If I want to make a module where each component function **and class** has its own file in the module folder (to make editing neater), how do I get this to work so that functions can access each other **and** all can use the classes?

I’ve read stuff where a PSM1 dot-sources separate files and exports their functions explicitly, and also references to specifying the files as Nested Modules in the PSD1. The latter seems to have issues with functions accessing each other unless you have multiple PSD1s - which seems a bit excessive if each nested “module” is going to contain only one function that you’d never be importing on its own.

I’ve not seen any reference to this topic where classes are specifically brought into it too. I need the classes to be usable both by the functions and also their being “exportable” by the module (i.e. visible to “using module”).

Thanks for any thoughts from anyone who’s battled with this already!

---

<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 9, 2019, 1:37pm UTC](https://forums.powershell.org/t/multi-file-modules-with-classes/13111/2 "2019-09-09T13:37:50Z")

</div>

Classes cannot be exported from a module unless they are located directly in the `psm1` file. There really isn’t a workaround there, you need them in the module file itself, before any functions are dot sourced.

---

<div class="post-metadata">

**Author:** ![cantoriscomputing](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/cantoriscomputing/32/179_2.png) [@cantoriscomputing](https://forums.powershell.org/u/cantoriscomputing)\
**Post date:** [September 9, 2019, 1:58pm UTC](https://forums.powershell.org/t/multi-file-modules-with-classes/13111/3 "2019-09-09T13:58:18Z")

</div>

Thanks Joel! That’s unfortunate but I guess it’s understandable ☹

---

<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 9, 2019, 3:13pm UTC](https://forums.powershell.org/t/multi-file-modules-with-classes/13111/4 "2019-09-09T15:13:50Z")

</div>

If you want to develop the module having classes in separate files as well, you might implement a build step as part of a release pipeline where all class files’ contents are collated along with necessary parts of the PSM1 and you put together a new PSM1 before you release the module and use it in production.

---

<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:31pm UTC](https://forums.powershell.org/t/multi-file-modules-with-classes/13111/5 "2024-05-16T20:31:42Z")

</div>

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


