I have this script to connect to a SharePoint online site using username & password:
$encpassword = convertto-securestring -String "********" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "****@******.com", $encpassword
Connect-PnPOnline -Url https://******.sharepoint.com/ -Credentials $cred
But I am getting this error:
Connect-PnPOnline : AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a
new location, you must use multi-factor authentication to access '00000003-0000-0ff1-ce00-000000000000'.
Trace ID: 0e616060-9737-4793-a2df-6dc7e1695000
Correlation ID: 6102bb1c-1b28-4979-994e-83ddb5ddf6e9
Timestamp: 2022-12-07 19:09:26Z
At line:1 char:1
+ Connect-PnPOnline -Url https://****.sharepoint.com/ -Credent ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-PnPOnline], MsalUiRequiredException
+ FullyQualifiedErrorId : Microsoft.Identity.Client.MsalUiRequiredException,PnP.PowerShell.Commands.Base.ConnectOn
line
Can anyone advice on this please?