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
View all comments
Show parent comment
1
u/jdl_uk Dec 17 '25 edited Dec 17 '25
It's not identical at all
Suppose I have this script:
Getting completion on the
Do-Somethingfunction and its parameters requires that I run the script. If I change something in that function in that module, I have a song and dance about getting that change imported (I think sometimes I've had to actually restart the extension shell).This module is also not auto-imported even if auto importing is enabled because it's not in
$PSModulePathand that's deliberate because its use is to be called as part of this script.Auto-importing modules would also import more than this relevant module which would be undesirable (particularly if you have Azure or AWS modules installed because they're huge).
The same would mostly be true of modules imported using
Import-ModuleNow compare that to this script:
Difference #1 - I get completion on that script call immediately and its parameters because the language server evaluates the script file without me needing to import anything.
Difference #2 - Changes also automatically apply, so I don't need to do anything to make that happen.
Difference #3 - This solution doesn't require me to enable any global settings.
So that's not really identical is it?
As I said, this could be fixed by the language server (not the extension shell) importing modules based on your
using modulestatements (and maybe#Requires -Module) but it doesn't do that. So I'm thinking of moving to the script based approach.Edit: one thing I didn't mention because I thought was obvious but maybe wasn't was that the script doesn't contain the function, the script is the function, with the
[CmdletBinding]andparamstatements at its root, like this: