Everything seems correct:
- The path is correctly set to find your PowerShell module (normally C:\Program
- 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
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.
No solution, but only workarounds:
- First 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 220.127.116.11 folder directly in the PSWindowsUpdate
folder and it works!
- Another workaround: Import the module with the full path to the psd1 or psm1
Import-Module 'C:\Program Files\WindowsPowerShell\Modules\PSWindowsUpdate\18.104.22.168\PSWindowsUpdate.psd1'
One thought on “[Solved] No valid module file was found in any module directory”
Thank you for your help sir, saved me from madness 🙂
LikeLiked by 1 person