I have a powershell script running in a .NET Core 3.1 (C#/PowerShell) runtime in AWS. I'm unable to use Install-Module
to install modules. When I try, for example, to run Install-Module ExchangeOnlineManagement
I get the following error:
[Error] - The term 'Install-Module' is not recognized as the name of a cmdlet, function, script file, or operable program.
How do I get around this? I'm deploying my code from a local project using terraform and gitlab-ci. Do I need to somehow include the modules in my project itself so that they get zipped up and deployed with my script?
UPDATE:
I tried adding a '/modules' folder to the '/lambda_code' folder of my lambda project (and manually pasted the desired module into that folder). Now when I run 'Install-Module ExchangeOnlineManagement' I get:
[Error] - The specified module 'ExchangeOnlineManagement' was not loaded because no valid module file was found in any module directory.
It seems I am not putting the module in the right path.
I added the following logs to my script to discover where to put the module:
$modulePath = $ENV:PSModulePath
Write-host "This is the PSModulePath ${modulePath}"
Which printed:
[Information] - This is the PSModulePath /tmp/765bd878-da6c-4275-a378-78de284fb3e3/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/var/task/Modules
I don't see how to use that information. Input is welcomed! thank you.
[Information] -
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Linux 4.14.255-276-224.499.amzn2.x86_64 #1 SMP Tue May 3 22:30:10 UTC 2022
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
I also tried forcing the Import command to look in the /module folder:
Import-Module –Name \modules\ExchangeOnlineManagement -Verbose
But that returned:
The specified module was not loaded because no valid module file was found in any module directory.