Or, open the admin center with the user for which you want to enable MFA authentication. Navigate to here.
From the above figure, you can see we have successfully enabled multi-factor authentication for the user named “test”.
In our blog, we will see how to work with MFA authentication using PowerShell. Basically, we provide the user's username and password credentials in the PowerShell script to retrieve the client context object. If we will use the same procedure with MFA to enable user account, it will show an exception while executing the client context.
"Execute Query" with "0" argument(s): "The sign-in name or password does not match one in the Microsoft
account system."'
In MFA authentication, we use $authManager.GetWebLoginClientContext to retrieve the context. Executing this line opens the authentication window and asks for login credentials and acknowledged call/ text message to verify authentication from the script.
Note
Make sure you have installed the latest version of SharePoint, i.e., SharePointPnPPowerShellOnline.msi in your system and added all the dlls of latest versions. You can download the OfficeDevPnP.Core.dll,Microsoft.IdentityModel.Clients.ActiveDirectory.dll package from these links.
- https://www.nuget.org/packages/SharePointPnPCoreOnline/2.26.1805.1
- https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory/2.29.0
Download the packages, rename that (add .zip extension with it), and save. Extract it to use the dlls in scripts.
In this blog, we are going to create a custom list with MFA authentication.
The code block for this is mentioned below.