liveBook · Manning

Import-Module

As explained in Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools

Import-Module is a PowerShell cmdlet that loads a module and its exported commands into a session.

Import-Module loads a PowerShell module and its commands into the current session. Provide the full path when testing a specific module version or loading code outside standard module locations. section 10.2

Use these practices when developing or testing modules:

  • Run Remove-Module before loading another version, or use Import-Module -Force to overwrite existing commands. section 10.2
  • Reload after editing because PowerShell runs the imported module from memory rather than rereading the file automatically. section 10.4
  • Test in a standard PowerShell console so the execution environment matches production more closely. section 10.4

Reload a changed module

Import-Module ScriptingMOL -Force section 10.4

$env:PSModulePath

Inspect the module search path when deciding whether Import-Module can discover a module by name. section 10.4

How Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools covers it

How deep it goes
Explains path-based loading, forced reimport, and in-memory behavior without detailing module internals.
Examples
Uses a ScriptingMOL module, full-path loading, Remove-Module, and Import-Module ScriptingMOL -Force.
What you can do after
Operate/configure PowerShell sessions by loading, replacing, and refreshing script modules.
How it connects
Connects module loading with Remove-Module, module discovery, PSModulePath, and execution policy.

Also explained in

Compare how 2 books explain Import-Module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools. The section links point to the parts of the book it draws on.