r/PowerShell • u/samurai_ka • Dec 17 '25
Question Multiple files
Unfortunately, large PowerShell scripts cannot easily be distributed across multiple files in a project. What is your best strategy for this?
6
Upvotes
11
u/psdarwin Dec 17 '25
This sounds like a job for a PowerShell module
https://learn.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-script-module?view=powershell-7.5
10
u/jungleboydotca Dec 17 '25
I'm not clear on what you mean, what is the difficulty exactly?
6
u/Sweaty-Move-5396 Dec 17 '25
Sure they can. Did you try?
5
u/Future-Remote-4630 Dec 17 '25
This thread reminds me of the stackoverflow trick, where instead of asking for help which was often met with gatekeeping, they instead provide the wrong answer as the solution, prompting the community to correct them.
Props op, it worked. Use a module.
https://learn.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-script-module?view=powershell-7.5
2
u/reinderr Dec 17 '25
You could make it into a module, that way you can just autoload it when you call a command
2
u/jdl_uk Dec 17 '25
I've been using modules and lots of use of validation attributes on parameters.
I am considering moving more towards using scripts as functions (which I would once have considered an antipattern) because parameter auto completion will work without having to do anything, while modules need me to import the module, and it also handles changes to those functions better than changes to modules.
2
u/deadflamingo Dec 17 '25
Create a psm1 and get back to me.
1
u/CyberChevalier Dec 18 '25
Module, PS repository on a share
1
u/Ummgh23 Dec 19 '25
Start writing Modules!
0
u/Over_Dingo Dec 17 '25
\s