connect PnPOnline to add file to SharePointonline

I am not able to connect to sharepoint using below script

$Mycredentials = Import-Clixml -Path “file1.xml”

Connect-PnPOnline -Url $SiteUrl -Credentials $Mycredentials

Add-PnPFile -Folder “folder1” -Path “file2.csv”

Can you post the error message?

Connect-PnPOnline : Object reference not set to an instance of an object.
At line:12 char:1

  • Connect-PnPOnline -Url $SiteUrl -Credentials $Mycredentials
  • CategoryInfo : NotSpecified: (:slight_smile: [Connect-PnPOnline], NullReferenceException
  • FullyQualifiedErrorId : System.NullReferenceException,PnP.PowerShell.Commands.Base.ConnectOnline

Add-PnPFile : Cannot contact site at the specified URL The app principal does not
At line:21 char:1


<Objs Version=“” xmlns=“”>
<Obj RefId=“0”>
<TN RefId=“0”>
<S N=“UserName”></S>
<SS N=“Password”>5aebd577fb6a140000006c4a0eb6f61bb18e6d200d7c8d3ee98685587b9d</SS>

Also the account is set to use MFA.

CAn that be an issue?


I can connect to sharepoint with useWeblogin fine.

I think MFA requires the -UseWebLogin switch. From the docs:


If you want to connect to SharePoint with browser based login. This is required when you have multi-factor authentication (MFA) enabled.

The xml file is fine. Try adding this switch to your Connect-PnPOnline command.

This may not allow you to specify the credentials in the command because it is in a different parameter set....