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:

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

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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With