I have a custom script module and one of the functions depends on the AWSPowerShell module. I attempted to put Import-Module AWSPowerShell
inside that function, but when this runs on the server it fails and says no valid module is found. If I try Import-Module AWSPowerShell
from the command line on the same server running as the same user it works fine. There seems to be something wrong with calling Import-Module
from inside another module.
I saw that NestedModules can be used to specify dependencies so I added NestedModules @('AWSPowerShell')
to the module manifest and removed the Import-Module AWSPowerShell
from the function that needs it.
Now the error about AWSPowerShell happens at the point where I import my own custom module from the calling script.
The exact error is: Import-Module : The module to process 'AWSPowerShell', listed in field 'NestedModules' of module manifest 'C:\Program Files\WindowsPowerShell\Modules\...MyModule.psd1' was not processed because no valid module was found in any module directory.
I did notice that the AWSPowerShell module is installed in a different folder path than my custom module. My module is in C:\Program Files\WindowsPowerShell\Modules
and AWSPowerShell is in C:\Program Files (x86)\AWS Tools\PowerShell
.
How can I set this up so that AWSPowerShell can be loaded for use inside my module?
Update
I made a copy of the AWSPowerShell module folder under C:\Program Files\WindowsPowerShell\Modules
and now the module imports successfully using the NestedModules method. Everything I saw about NestedModules appeared to be for combining modules that were being developed for a bigger solution. I'm not sure about using this technique for importing a 3rd party module like this. I may be misusing this feature.