Skip to content

/errors/powershell/no-valid-module-file-was-found

The specified module 'x' was not loaded because no valid module file was found in any module directory.

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
PowerShell
exit code
1
versions
Windows PowerShell 5.1, PowerShell 7.x
os
windows, linux, macos

Import-Module : The specified module 'Name' was not loaded because no valid module file was found in any module directory. means PowerShell looked for a folder called Name with a Name.psd1, Name.psm1 or Name.dll in every folder of $env:PSModulePath, and found none. Either the module is not installed, or it is installed somewhere this PowerShell edition and user do not look. Check with Get-Module -ListAvailable Name; install it, or import it by its full path.

Reproduce it

powershell
$ErrorActionPreference = 'Stop'
try { Import-Module NoSuchModule } catch { $_.Exception.Message; '  -> ' + $_.FullyQualifiedErrorId }
New-Item -ItemType Directory -Path mods\Hello | Out-Null
Set-Content mods\Hello\Hello.psm1 'function Get-Hello { "hello from module" }'
Import-Module .\mods\Hello\Hello.psm1
Get-Hello
Remove-Module Hello
$env:PSModulePath = (Join-Path $PWD 'mods') + [IO.Path]::PathSeparator + $env:PSModulePath
Import-Module Hello
(Get-Module Hello).Name

Output

The specified module 'NoSuchModule' was not loaded because no valid module file was found in any module directory.
  -> Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
hello from module
Hello

Importing by path always works if the files are valid; importing by name works only when the module's parent folder is on PSModulePath.

Where modules are searched

FolderWindows PowerShell 5.1PowerShell 7
Current userDocuments\WindowsPowerShell\ModulesDocuments\PowerShell\Modules
All users$env:ProgramFiles\WindowsPowerShell\Modules$env:ProgramFiles\PowerShell\Modules
Built-in$PSHOME\Modules (System32\WindowsPowerShell\v1.0\Modules)$PSHOME\Modules

PowerShell 7 on Windows also includes the Windows PowerShell folders in its path, so most 5.1 modules are found there; the reverse is not true. See PSModulePath.

  • ActiveDirectory, GroupPolicy, DnsServer: part of RSAT. On Windows 11 install the optional feature; see install RSAT on Windows 11.
  • Hyper-V, ServerManager, other server roles: installed with the Windows feature or role.

Sources