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 26, 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
farismalaeb
Apr 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 here
https://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..