Let’s Connect to SPO using PnP Powershell . So, First thing we need to do this to install SharePointPnPPowerShellOnline module with the help of the command below:
To run that open your Windows PowerShell and run as administrator and then paste or type the above command and press enter.
If you get the below error while running the command. Then it could be because of the execution policy is set to restricted.
To Resolve the above error please set your execution policy to unrestricted. To do that run your PowerShell as Admin privileges and run the following command:
Set Execution Policy to Unrestricted
Set-ExecutionPolicy Unrestricted -Scope LocalMachine
Please type ‘Y’ to confirm.
This will set the Execution Policy to be unrestricted for the Local Machine scope.
Now we are ready to Install the Module.
Install SharePointPnPPowerShellOnline Module
While running above command if get any untrusted repository message the please Type ‘Y’ and press enter.
To Check which version of the module is installed please type the command below :
Get-Module SharePointPnPPowerShellOnline -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending
If already have the module installed and you want to update it to the latest version then please run the below command.
Update the Module
Connect To Sharepoint Online Site:
Connect-PnPOnline –Url https://tenantname.sharepoint.com/sites/SiteName –Credentials (Get-Credential)
If you’re using MFA then use
Connect-PnPOnline –Url https://tenantname.sharepoint.com/sites/SiteName –UseWebLogin
Enter Your credentials in the Pop-up Box and press Ok.
After that you are connected to your tenant and to test you can run:
Which will give the lists present in the site.
Recently while connect to My tenant I got this warning message :
So, the message says I am running the legacy version of PnP PowerShell which is going to be archived soon.
To install the newer version, I had to Uninstall the legacy version by using.
Uninstall-Module -Name SharepointPnPPowerShellOnline -AllVersions -Force
And then Install the newer version with Below command.
Install-Module -Name PnP.PowerShell
So whoever is installing the PnPPowerShell module the first time it is recommended to use the newer version of the same.
So above all were the PowerShell command to Connect to SPO using PnP PowerShell.
Go Back to Home