M365 – Resolving error – Connect-PnPOnline : The term ‘Connect-PnPOnline’ is not recognized as the name of a cmdlet, function, script file, or operable program
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
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
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
I would say yes – “y” and go ahead. Then next warning 🙂 It will be regarding – “Untrusted repository” as shown in below fig
I would again for an option yes – “y” and downloading and installing for the “
SharePointPnPPowerShellOnline” module will be started as shown in below fig
Once the “
SharePointPnPPowerShellOnline” module installed successfully we could execute the Connect-PnPOnline command successfully 🙂
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 🙂