Problem: When trying to run a PowerShell script for SharePoint Online, I got this error message:
“Connect-PnPOnline : 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.”
Case 1: PnP PowerShell Module is not Installed
Usually, this error occurs when you don’t have the PnP PowerShell module for SharePoint Online is installed on the local machine. So, to get rid of this error, you must install “PnP.PowerShell” module as:
More information on installing the PnP PowerShell module for SharePoint Online is here: How to Install PnP PowerShell Module for SharePoint Online?
Case 2: Multiple Versions of PnP PowerShell Module is installed and there is a Conflict!
In some cases, this error could be because of multiple versions of the SharePoint Online PnP PowerShell module installed and conflicting! Close all running instances of PowerShell and PowerShell ISE, Open a new PowerShell window as Administrator, and run these steps:
- Step 1: Get All Installed versions of classic SharePoint Online PnP PowerShell
- Step 2: Uninstall All Installed SharePoint Online PnP PowerShell Modules
Uninstall-Module SharePointPnPPowerShellOnline -AllVersions -Confirm:$False
- Step 3: Install the latest versions of SharePoint Online PnP PowerShell