M365 – Resolving error – Connect-PnPOnline : The term ‘Connect-PnPOnline’ is not recognized as the name of a cmdlet, function, script file, or operable program

M365 - Connect-PnPOnline - Downloading / Installing module - SharePointPnPPowerShellOnline
M365 - Connect-PnPOnline - Downloading / Installing module - SharePointPnPPowerShellOnline

Hi All,

LIFE IS BEAUTIFUL  🙂 I hope we all are safe 🙂 STAY SAFE, STAY HEALTHY,  STAY HOME 🙂 

Background: In one of my background application / job using CSOM code I was trying to get the Client Context using the method

return new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(url, realm, appId, secret);

Even though Azure app has full permissions, I was getting an exception – System.Net.WebException: The remote server returned an error: (401) Unauthorized.

So I thought I’ll try to connect once using Connect-PnPOnline cmdlet as

PS C:\> Connect-PnPOnline -Url "https://knowledgejunction.sharepoint.com/sites/Configuration/"  -Realm "tenantid" -AppId "appid"  -AppSecret "clientsecretkey" 

On execution of above command I am getting an following exception

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.
At line:1 char:1 Connect-PnPOnline -Url “https://knowledgejunction.sharepoint.com/sites/Configur …Connect-PnPOnline -Url “https://knowledgejunction.sharepoint.com/sites/Configur …CategoryInfo : ObjectNotFound: (Connect-PnPOnline:String) [], CommandNotFoundException FullyQualified ErrorId : CommandNotFoundException

M365 - Connect-PnPOnline - error - The term 'Connect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program
Fig: M365 – Connect-PnPOnline – error – The term ‘Connect-PnPOnline’ is not recognized as the name of a cmdlet, function, script file, or operable program

Error / Issue : PowerShell module for PnP cmdlets – “SharePointPnPPowerShellOnline” is not installed on my laptop.

Solution: Install the module “SharePointPnPPowerShellOnline“. Execute the following PowerShell cmdlet

Install-Module -Name "SharePointPnPPowerShellOnline"

It might give a warning for NuGet provider as

M365 - Connect-PnPOnline - Installing module - SharePointPnPPowerShellOnline
Fig: M365 – Connect-PnPOnline – Installing module – SharePointPnPPowerShellOnline

I would say yes – “y” and go ahead. Then next warning 🙂 It will be regarding – “Untrusted repository” as shown in below fig

Fig: M365 - Connect-PnPOnline - Installing module - SharePointPnPPowerShellOnline
Fig: M365 – Connect-PnPOnline – Installing module – SharePointPnPPowerShellOnline

I would again for an option yes – “y” and downloading and installing for the “SharePointPnPPowerShellOnline” module will be started as shown in below fig

Fig: M365 - Connect-PnPOnline - Downloading / Installing module - SharePointPnPPowerShellOnline
Fig: M365 – Connect-PnPOnline – Downloading / Installing module – SharePointPnPPowerShellOnline

Once the “SharePointPnPPowerShellOnline” module installed successfully we could execute the Connect-PnPOnline command successfully 🙂

References :

Thanks for reading  🙂 Feel free to discuss / comment / questions 🙂 SHARING IS CARING 🙂

Share In Teams:

Enjoy the beautiful life 🙂 Have a FUN 🙂 HAVE A SAFE LIFE 🙂 TAKE CARE 🙂 

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: