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

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 πŸ™‚ 

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