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 126.96.36.199 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\188.8.131.52\PSWindowsUpdate.psd1'