Connect-PnPOnline demystified
So here goes: the long list of all ways to authenticate with PnP PowerShell, including some tips
##Credentials This is the most common way and I assume that many of you start off using this method.
Connect-PnPOnline -Url https://contoso.sharepoint.com
If you have not done any set up in the Windows Credential Manager, then executing the cmdlet like will popup a prompt for a username and password. It’s the easiest way to authenticate
##Credentials by specifying them in a variable
$creds = Get-Credential
Connect-PnPOnline -Url https://contoso.sharepoint.com -Credentials $creds
##Credentials by automatically loading them from the Credential Manager There are several ways to set this up.
First the difficult/manual way: On Windows 10 the easiest way to launch the Credential Manager is by simply pressing the Windows/Start button and start type ‘Credentia’. Most likely the first hit you get is the Credential Manager. If you are on other versions of Windows, navigate to Control Panel, You’ll find the Credential Manager in there.
Click ‘Windows Credentials’, and add a Generic Credential (it’s the 3rd section from the top). Enter the base url of your tenant, e.g. https://contoso.sharepoint.com, enter your username and your password.
Click okay. Now if you use Connect-PnPOnline
and your URL starts with the URL you specified in the credential manager entry, it will use those credentials to authenticate. This will really make it simple to create to use PnP PowerShell in unattended automation tasks. Notice that using this trick you can also specify different username/password combinations for different sites. Just enter more complete URLs, alike https://contoso.sharepoint.com/sites/mysite, etc. in the Credential Manager.
Now the somewhat easier way, requiring less clicking
As of the March 2018 of PnP PowerShell there is a cmdlet called Add-PnPStoredCredential
. Using that one it’s very easy to add a URL to the Windows Credential Manager.