0

I'm trying to run a powershell script with the Windows task scheduler. The script works perfectly when I run it manually. But receive the following error when executed (with highest privileges) in the Windows task scheduler:

Error while connecting to site 'https://####':The term 'Connect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."

I've reinstalled the Pnp PowerShell assembly from here: https://github.com/SharePoint/PnP-PowerShell/releases and verified if the modules are installed correctly with:

Get-Module SharepointPNPPowershellOnline
  • import-module in the beginning of the script? As i presume that you do not use your own account to run the scheduled task. – Christoffer Jun 23 at 10:20
-1

Try to execute the same script from the PowerShell ISE or PowerShell command prompt.... if it works it's fine, then some problems on windows task scheduler. And if it doesn't work then PnP PowerShell model did not get installed properly, then try to reinstall the PnP PowerShell module again.

There are many ways we can install the PnP PowerShell for SharePoint online - the simplest way to run the below command in your machine:

(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/sharepoint/PnP-PowerShell/master/Samples/Modules.Install/Install-SharePointPnPPowerShell.ps1')

For details prerequisites and installation refer to the below article:

Office 365: Getting started with SharePoint PnP PowerShell – installation

| improve this answer | |
  • The question is clearly not about how to install the PnP PowerShell module. – Christoffer Jun 23 at 10:21
  • @Christoffer - It looks strange to see downvoting, if we install the PnP PowerShell module properly we don't need to include the "import-module" in the beginning of the script - I do execute plenty of PnP scripts on daily basis, I don't include "import-module", still it works. That is the reason I have added how to install the PnP PowerShell module. – Habibur Rahaman Jun 23 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.