Connect-PnPOnline Issue with -Credentials
Reporting an Issue
I am having trouble with the cmdlet Connect-PnPOnline all of a sudden.
I was using Windows autentication manager with a generic autentication :
Label : "MyOrg', email : "[email protected]", password : "MyPassWord"
So I call Connect-PnPOnline -Url 'https://myorg.sharepoint.com/sites/MySite' -Credentials MyOrg but this leads to an error.
I then tried several things :
- using only -Credentials Get-Credentials to prompt the pop up to enter the creds. Throws the same error
- using -UseWebLogin param instead of -Credentials. It works like a charm.
I do not want to use Web Login, because the script will be stored as a scheduled task, so no human will enter some creds.
The different code I used are in the Steps to reproduce.
Expected behavior
Connecting to the URL given in parameters, so I can perform some actions.
Actual behavior
Does not connect to given URL. Throws an error :

Connect-PnPOnline : La référence d'objet n'est pas définie à une instance d'un objet. Au caractère Ligne:7 : 1 ++ Connect-PnPOnline -Url $sommaireURL -UseWebLogin ++ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ++ CategoryInfo : NotSpecified: (:) [Connect-PnPOnline], NullReferenceException ++ FullyQualifiedErrorId : System.NullReferenceException,SharePointPnP.PowerShell.Commands.Base.Connec tOnline
Steps to reproduce behavior
Here is the code I used :
`Import-Module "$(get-location)\pnpmodules\3.10.1906.0\Modules\SharePointPnPPowerShellOnline\SharePointPnPPowerShellOnline" -Verbose:$false -DisableNameChecking
$orgName='myorgname'
$siteURL = "https://myorgname.sharepoint.com/sites/MySite"
Connect-PnPOnline -Url $siteURL -Credentials $orgName
##then, trying with only Get-Credentials :
Connect-PnPOnline -Url $siteURL -Credentials Get-Credentials`
Which version of the PnP-PowerShell Cmdlets are you using?
- [ V ] PnP PowerShell for SharePoint Online
What is the version of the Cmdlet module you are running?
SharePointPnPPowerShellOnline v 3.10.1906.0
How did you install the PnP-PowerShell Cmdlets?
- [ V ] MSI Installed downloaded from GitHub
Please help me with this, I don't know what to do, it worked like a charm before last week.
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
LegacyAuthProtocolsEnabled must be true on your tenant. Run the command “Get-SPOTenant”. Check the property “LegacyAuthProtocolsEnabled”. If this is set to true then Legacy Authentication is enabled else disabled.
This method has been working for me. I have the user and password stored in environment variables to keep them out of source control.
$SecurePass = $Env:SharepointPassword | ConvertTo-SecureString -AsPlainText -Force
Add-PnPStoredCredential -Name MyUser -Username $Env:SharepointUser -Password $SecurePass
Connect-PnPOnline -Url $SiteUrl -Credentials 'MyUser'
It is honestly better to set up Application Authentication for a scheduled task. https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs Follow these instructions then you can connect using
Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/mysite" -AppId "AppId" -AppSecret "AppSecret"