I have a big CSOM powershell script which is using basic authentication. This script is scheduled to run every day. This script is using credentials of a serviceaccount without MFA. We would like to disable basic authentication, but this script needs to be modified. I dont want to rewrite the whole CSOM script to Office Dev PnP Powershell because it is a big script.

What is the easiest way to move from basic to modern authentication in a CSOM powershell script?

See below a small part with authentication and some SPO logic:

$lo_ClientContext             = New-Object Microsoft.SharePoint.Client.ClientContext( https://myCompany.sharepoint.com/sites/test )
$lo_ClientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials( [email protected], myPassword )

$ll_Lijst = $lo_ClientContext.Web.Lists.GetByTitle( "myList" )
$lo_ClientContext.Load( $ll_Lijst )
  • Please who can help me?
    – Jackson
    Feb 8, 2022 at 11:47
  • Sorry this isn't an answer but I dont have the reputation to comment. I have the same problem. I've checked and setting up Modern/Basic Authentication is Organisation wide. I.e. its not possible to create a new account allowing legacy connections. Did you find a fix? Feb 23, 2023 at 20:18

1 Answer 1


Easy way. Make a new account that allows legacy connections, disable MFA for it, and only turn it on before the script is ran, and then turn it off after.

It's a workaround, but likely easier than updating all your scripts to use azure app keys

  • Hi, this script is not for only run it one time. It will be scheduled to run every day.
    – Jackson
    Feb 22, 2022 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.