[Solved] No valid module file was found in any module directory

Problem context

Everything seems correct:

  • The path is correctly set to find your PowerShell module (normally C:\Program Files\WindowsPowerShell\Modules)
  • Your PowerShell module was correctly build
    • Your files are in a subfolder of the C:\Program Files\WindowsPowerShell\Modules folder
    • the PSM1 and PSD1 (if you created one) files have the same name as the folder name
  • Your module is working fine on servers later than Windows 2008 R2
  • However, on Windows 2008 R2 servers, you get the following error:
    Import-Module : The specified module 'pswindowsupdate' was not loaded because no valid module file was found in any module directory.
        + CategoryInfo          : ResourceUnavailable: (pswindowsupdate:String) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

The reason

I didn’t find out why, but the fact is that even if you install PowerShell 5.1 on Windows 2008 R2 server, they don’t discover modules that have sub-versions in subfolders.
For instance, in the following screenshot, you can see four different valid versions of the PSWindowsUpdate module.

This works fine on Windows 2012 servers or later, but unfortunately not on Windows 2008 R2 servers.

The workaround

No solution, but only a workaround:
Copy all the content of the version you want to use directly in the module’s main folder.
In my example above, I copied all files from the 2.0.0.4 folder directly in the PSWindowsUpdate folder and it works!

More about

How to Write a PowerShell Script Module (MSDN)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s