How to Fix 'Module Not Found' Error in PowerShell
The
Module Not Found error in PowerShell happens when the module is not installed or not in the module path. Fix it by installing the module with Install-Module and importing it using Import-Module with the correct name or path.Why This Happens
This error occurs because PowerShell cannot find the module you want to use. It might be missing from your system or not located in the folders PowerShell checks for modules.
powershell
Import-Module NonExistentModule
Output
Import-Module : The specified module 'NonExistentModule' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module NonExistentModule
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (NonExistentModule:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
The Fix
First, install the module if it is not installed using Install-Module. Then, import it by its exact name. This ensures PowerShell can find and load the module correctly.
powershell
Install-Module -Name PowerShellGet -Force -Scope CurrentUser Import-Module PowerShellGet Get-Module PowerShellGet
Output
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.2.5 PowerShellGet {Find-Module, Install-Module, Save-Module, Update-Module...}
Prevention
Always check if the module is installed before importing. Use Get-Module -ListAvailable to see installed modules. Keep your PowerShell updated and install modules from trusted sources. Avoid typos in module names and use the exact module name when importing.
Related Errors
Other common errors include:
- Command Not Found: Happens when a cmdlet inside a module is not recognized because the module is not imported.
- Permission Denied: Occurs if you lack rights to install or import modules; run PowerShell as administrator or use
-Scope CurrentUser.
Key Takeaways
Install missing modules using Install-Module before importing.
Use Import-Module with the exact module name to load it.
Check installed modules with Get-Module -ListAvailable.
Run PowerShell with proper permissions to install or import modules.
Avoid typos and verify module names carefully.