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 Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

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