1

I am using below code to connect to SPO from powershell, but we have multi factor authentication in SharePoint.

So I want to give credentials from browser instead of script. Please suggest as i dont want to use PnP and Connect-SPOService due to environment restrictions.

{
    $ctx=New-Object Microsoft.Sharepoint.Client.ClientContext($webUrl)
    $ctx.Credentials=New-Object Microsoft.Sharepoint.Client.SharePointOnlineCredentials($userName,$password)
        return $ctx
}
1

You should create an app password for your user using these steps. Then you will be able to connect using your username and app password instead of a real password.

  • Isn't there any other way to do that, as probably our client will not permit me to create app password and i have to run this powershell script from a remote machine? After entering the email address in during logging in to SPO site, it asks our domain\userid and password again in a pop up, so i assume this is not a multi-factor authentication. – Adarsh Awasthi Dec 14 '18 at 17:11
  • Ah I got it. No it's not MFA – Sergei Sergeev Dec 14 '18 at 17:32
  • 1
    I'm not aware of any other good way to do that when MFA is enabled. The other way is PnP-PS of course, but you can't use it... – Sergei Sergeev Dec 14 '18 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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