Unable to run PnP PowerShell from a Task Scheduler

%3CLINGO-SUB%20id%3D%22lingo-sub-59740%22%20slang%3D%22en-US%22%3EUnable%20to%20run%20PnP%20PowerShell%20from%20a%20Task%20Scheduler%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59740%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20schedule%20a%20PnP%20PowerShell%20script%20from%20a%20Task%20Scheduler%20on%20a%20server.%20%26nbsp%3BI%20have%20installed%20the%20PnP%20module%20on%20the%20server.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20manually%20run%20the%20script%20in%20PowerShell%20or%20in%20the%20ISE%2C%20the%20script%20run%20fines%2C%20but%20when%20I%20try%20to%20run%20it%20from%20the%20Task%20Scheduler%2C%20it%20is%20%22unaware%22%20of%20the%20PnP%20commands.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20tried%20adding%20an%20%22Import-Module%20SharePointPnPPowerShellOnline%22%20to%20the%20script%20to%20no%20avail.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20advice%20for%20solving%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-59740%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-59753%22%20slang%3D%22en-US%22%3ERe%3A%20Unable%20to%20run%20PnP%20PowerShell%20from%20a%20Task%20Scheduler%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59753%22%20slang%3D%22en-US%22%3ESet%20%24env%3APSModulePath%20to%20include%20your%20pnp%20power%20shell%20folder.%3C%2FLINGO-BODY%3E
Valued Contributor

I am trying to schedule a PnP PowerShell script from a Task Scheduler on a server.  I have installed the PnP module on the server.

 

If I manually run the script in PowerShell or in the ISE, the script run fines, but when I try to run it from the Task Scheduler, it is "unaware" of the PnP commands.

 

I've tried adding an "Import-Module SharePointPnPPowerShellOnline" to the script to no avail.

 

Any advice for solving this?

1 Reply
Set $env:PSModulePath to include your pnp power shell folder.