0

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.

208_man
  • 1,440
  • 3
  • 28
  • 59
  • What is powershell version is this `$PSVersionTable` , are you sure its running powershell ? – Vasil Nikolov Aug 30 '22 at 20:05
  • @VasilNikolov see update to post. PSVersion is 7.0.0 – 208_man Aug 30 '22 at 22:49
  • Use Save-Module to get a portable version of the module. When you import-module point to the .PSD1. You can use Find-Module ExchangeOnlineManagement | Install-module to get it from the repo. – Aaron Aug 31 '22 at 01:43
  • Thank you @Aaron. Would you mind elaborating? Do I first run Save-module for ExchangeOnlineManagement and then import-module? Then the longer Find-Module... | Install-module command? I see four commands and would deeply appreciate more information on how to properly use your suggestions. Thank you! – 208_man Aug 31 '22 at 14:09
  • have you tried these suggestions - https://stackoverflow.com/questions/6412921/powershell-import-module-doesnt-find-modules – Vasil Nikolov Aug 31 '22 at 23:20

0 Answers0