Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Module not automatically loaded for Linux container

I have a Powershell module that looks like this this:

function SayHello
{
    echo "hello"
}

I saved it as say-hello.psm1 and added it to a dockerfile like this:

COPY --chmod=0755 say-hello.psm1 /root/.local/share/powershell/Modules/say-hello.psm1

When I start the docker image up, and run SayHello it tells me that it can't find the command:

SayHello not recognized

But if I then run an Import-Module command and try it again, it works:

Can work if imported manually

I thought that maybe I had the wrong folder, but when I run $Env:PSModulePath I get /root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules. According to the documentation, that is where the modules should go. (I put it in the first one)

What do I need to do to make my powershell module work without needing to be manually imported?

like image 284
Vaccano Avatar asked May 03 '26 20:05

Vaccano


1 Answers

I forgot that you need to put the psm1 file in a folder with the same name as the file (inside the Modules folder).

I did that and it started working just fine.

like image 152
Vaccano Avatar answered May 05 '26 09:05

Vaccano