Forum Discussion
HHarms
Apr 09, 2021Copper Contributor
"Pre load" Powershell module
My new Powershell module did have a load time of several seconds. Using this in a production environment is not an option with this long load time. Is it possible to add this module to the "core" o...
SteveMacNZ
Apr 27, 2021Iron Contributor
although adding the import-module into the PowerShell profile will load the module every time you open PowerShell it will add a several second delay to the PS console be usable, and depending on what profile you add the module to could effect every user that users that system (think RDS servers and the like) best case they might have a delay worse case they will get red errors due to access / permissions.
my biggest concern is what the module is actually doing - for example if we take Exchange and Exchange Online - the PowerShell modules are different - BUT the commands are the same - which could lead to major issues e.g. just deleting that brand new Exchange online mailbox rather than the on-prem one....
If the script is non interactive I personally wouldn't worry about the delay load up the module at run time - if the script is interactive provide the user some feedback (a percentage competed bar / write-host notification etc) to inform then of the delay
my biggest concern is what the module is actually doing - for example if we take Exchange and Exchange Online - the PowerShell modules are different - BUT the commands are the same - which could lead to major issues e.g. just deleting that brand new Exchange online mailbox rather than the on-prem one....
If the script is non interactive I personally wouldn't worry about the delay load up the module at run time - if the script is interactive provide the user some feedback (a percentage competed bar / write-host notification etc) to inform then of the delay
- farismalaebApr 27, 2021Steel Contributor
Hi
There is a Post I wrote about how to use a command from a module when there is a similar command in another module
check it from herehttps://www.powershellcenter.com/2020/12/01/get-vm-conflict-between-hyper-v-ps-and-powercli/
but in a summary, you will need to call the module name\the command.
Loading PowerShell module will sure take time, if you have something related to RDS and its must be loaded, then you need to make sure that the command are loading in async mode, not sync..- SteveMacNZApr 27, 2021Iron Contributoragreed that is a good way to handle them in a script. I was more pointing out the dangers of having a module always loading in PowerShell profile - as those commands are always available. things like prefix when connecting can assist minimising these dangers. if you're loading in your own PowerShell profile that's fine you wear the risk and know what's going on.
Loading in the system profile other users may have no ideal and potentially do things with unexpected outcomes- farismalaebApr 28, 2021Steel ContributorTotally agree, even though it's still possible to add a prefix for a module.
https://www.sapien.com/blog/2016/02/15/use-prefixes-to-prevent-command-name-collision/
and it's also possible to prevent PowerShell from Autoload modules on startup, but this may have other impacts.
I was sooo confused when working with Exchange Online and Exchange On-prem the commands are similar and I needed both to be loaded as I was reading and comparing data from both.
I think it's better if the developer has a custom name for the module that reduces the possibility of having a conflict.