我的 powershell 配置文件中有一些模块,它们的加载有时需要很长时间(10-15 秒)。我想使用这样的方法将它们加载到后台线程中:
Start-Job -ScriptBlock { Import-Module -Global DockerCompletion }
问题是,即使文档声明 Import-Module 使用全局范围作为默认值,当我在父 shell 中使用 Get-Module 时,该模块并未列出,因此即使作业状态已完成,它也未加载。
我使用的一些模块:
Import-Module “$env:ChocolateyInstall\helpers\chocolateyProfile.psm1” -Force
Import-Module WSLTabCompletion
Import-Module posh-git
Import-Module npm-completion
Import-Module DockerCompletion
编辑:我正在使用 pwsh 7.1