0

Connect to SPO using PnP Powershell

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:

Install-Module SharePointPnPPowerShellOnline

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.

ExecutionPolicyerror

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.

Set-ExecutionPolicy

Now we are ready to Install the Module.

Install SharePointPnPPowerShellOnline Module

Install-Module  SharePointPnPPowerShellOnline

Press Enter

Connect to SPO using PnP Powershell

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
Connect to SPO using PnP Powershell

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

Update-Module SharePointPnPPowerShellOnline

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
Connect to SPO using PnP Powershell

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:

Get-PnPlist

Which will give the lists present in the site.

Recently while connect to My tenant I got this warning message :

Connect to SPO using PnP Powershell

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.

Reference : Connect-PnPOnline (PnP.Powershell) | Microsoft Docs

Go Back to Home

ravi

Leave a Reply

Your email address will not be published. Required fields are marked *