Have you ever run a PowerShell command and received the dreaded “The term is not recognized as the name of a cmdlet” error message? Here’s the kicker: the problem could be as simple as a missing or unimported module. Even in modern PowerShell versions, understanding how modules work is key to diagnosing and fixing these issues.
The good news? This guide covers everything from checking which modules PowerShell currently imported to mastering how to import, remove, and re-import them. By the end, you’ll skill up on seamlessly managing PowerShell modules, whether troubleshooting unexpected errors or working on custom modules.
Dive in and let PowerShell modules help you optimize your workflow with confidence!
Checking Imported Modules
PowerShell commands can fail with cryptic error messages when modules aren’t loaded properly. For example, trying to run Get-ADUser without first importing the ActiveDirectory module will result in a “command not found” error. Similarly, attempting to use Azure commands requires the Az module to be present in your session.
PowerShell must import the relevant module to ensure commands work as expected and make its commands available.
To view the currently imported modules, use:
Get-Module
When you run Get-Module, you’ll see output similar to this:
ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Manifest 7.0.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer...} Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable...} Script 2.0.0 PSReadline {Get-PSReadLineKeyHandler, Get-PSReadLineOption...} Binary 1.0.0.1 SmbShare {Get-SmbShare, Set-SmbShare, Remove-SmbShare...}
This displays a list of all currently loaded modules in your PowerShell session, showing their type (Manifest, Script, or Binary), version number, module name, and a summary of the commands they provide. The ExportedCommands column shows which cmdlets are available from each module.
Next, examine commands from a module that you can import:
Get-Module -Name SmbShare -ListAvailable | Select exportedcommands
When you run this command, you’ll see output that lists all the available commands in the SmbShare module. For example:
ExportedCommands ---------------- {Get-SmbShare, New-SmbShare, Remove-SmbShare, Set-SmbShare, Get-SmbShareAccess, Grant-SmbShareAccess, Block-SmbShareAccess, Revoke-SmbShareAccess, Get-SmbMapping}
This output shows all the cmdlets you can use from the SmbShare module. Each command serves a specific purpose for managing SMB shares:
- Get-SmbShare: Lists all SMB shares on the system
- New-SmbShare: Creates a new SMB share
- Remove-SmbShare: Deletes an existing SMB share
- Set-SmbShare: Modifies properties of an existing share
Understanding which commands are available helps you choose the right tool for your task. You can use similar commands to explore other modules’ capabilities.
Importing Modules Automatically
To see how PowerShell handles modules dynamically, here’s an example showing the dynamic module loading:
PS> Get-Module ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Manifest 7.0.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content...} Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type...} Script 2.0.0 PSReadline {Get-PSReadLineKeyHandler...} PS> Get-SmbShare PS> Get-Module ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Manifest 7.0.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content...} Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type...} Script 2.0.0 PSReadline {Get-PSReadLineKeyHandler...} Binary 1.0.0.1 SmbShare {Get-SmbShare, Set-SmbShare...}
As shown above, when you run Get-SmbShare, PowerShell automatically imports the SmbShare module. You can see this module appears in the list after running the command.
Removing and Re-importing Modules
You may need to clear a module from memory, such as when testing new configurations or resolving conflicts. If so, no worries; PowerShell lets you remove a module without uninstalling it, enabling you to reset or refresh the session as needed.
To remove a module from memory:
Remove-Module -Name SmbShare
The Remove-Module
cmdlet clears the module from memory but doesn’t uninstall it from your system. While removing modules is rare in everyday use, it’s useful for specific scenarios.
To manually import the module back:
Import-Module -Name SmbShare
Manual importing can be helpful when troubleshooting or working in custom environments.
Re-importing Modules After Changes
When working on a module under development, you may encounter situations where changes you make don’t immediately take effect. Old data or configurations may still be loaded in the module, causing this behavior.
Re-importing the module ensures that PowerShell uses the latest version. If you modify a module you’re developing, you must re-import it.
You could use both Remove-Module
and Import-Module
or simplify the process with the Force
parameter:
Import-Module -Name SmbShare -Force
The Force
parameter unloads and reloads the module in one step, making it ideal for development and testing workflows.
Conclusion
In this guide, you’ve learned how to manage PowerShell modules—checking imports and importing, removing, and re-importing modules. You also explored how PowerShell dynamically imports modules and how to control loading to troubleshoot or test custom configurations manually.
Now, apply these skills by experimenting with custom modules in your scripts. Explore module development and use the Force
parameter to ensure changes take effect.
Improve your troubleshooting, script development, and overall PowerShell workflow with PowerShell modules!