Issue
- I have an agent, windows server 2019, for my Jenkins.
- I have a task scheduler that starts the agent. by executing "javaws http://jenkins/computer/agentName/slave-agent.jnlp"
- I have a Jenkins job, with a step "Windows PowerShell", contains a command "Connect-PnPOnline"
The problem: I get the error "Get-PnPFile : The term 'Get-PnPFile' is not recognized as the name of a cmdlet"
However, when I start the agent by manually (instead of by executing the task) "javaws http://jenkins/computer/agentName/slave-agent.jnlp", then it works correctly
Solution
My Jenkins agent searched in "C:\Users\myUser\Documents\WindowsPowerShell\Modules" I copied PnP.PowerShell from C:\Program Files\WindowsPowerShell\Modules
I understood the problem by looking in $ENV:PSModulePath
Answered By - Rivka Altshuler
Answer Checked By - Pedro (JavaFixing Volunteer)