How to import modules in background in powershell?

750 Views Asked by At

I have a few modules in my powershell profile, and their loading sometimes takes a lot of time (10-15s). I would like to load them in a background thread using something like this:

Start-Job -ScriptBlock { Import-Module -Global DockerCompletion }

The problem is that even though the documentation states that Import-Module uses global scope as a default, when I use Get-Module in the parent shell the module is not listed, so it was not loaded even though the job states completed.

Some of modules I use:

Import-Module “$env:ChocolateyInstall\helpers\chocolateyProfile.psm1” -Force
Import-Module WSLTabCompletion
Import-Module posh-git
Import-Module npm-completion
Import-Module DockerCompletion

EDIT: I am using pwsh 7.1

0

There are 0 best solutions below