Skip to content

Instantly share code, notes, and snippets.

@altrive
Last active February 7, 2023 07:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altrive/6733868 to your computer and use it in GitHub Desktop.
Save altrive/6733868 to your computer and use it in GitHub Desktop.
Sample code to defer PowerShell modules loading.
#Register OnIdle event to load PS moduless.
Register-EngineEvent -SourceIdentifier ([Management.Automation.PsEngineEvent]::OnIdle) -MaxTriggerCount 1 -Action {
Import-Module TabExpansion++
#Import-Module FunctionExplorer
Import-Module VariableExplorer
Import-Module PSCodeAnalyzer.ISEAddin
Import-Module Altrive.ISEExtensions
#Remove current Job (No Need to get job result)
$EventSubscriber.Action | Remove-Job -Force -ErrorAction Ignore
#Note:PSModule Loading error is not returned.
} > $null
@michaelsanford
Copy link

This is 7 years old and I've only discovered it now!? It's incredibly useful. 👏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment