Set-MsolDeviceRegistrationServicePolicy is giving user_interaction_required: One of two conditions was encountered

2022-10-03T13:09:21.017+00:00

Hi Team,

The power shell command to set maximum devices per user is giving below error
code:
$pscredential = New-Object System.Management.Automation.PSCredential($userName, $userPassword)
Connect-MSOlService -Credential $pscredential
Set-MsolDeviceRegistrationServicePolicy -MaximumDevicesPerUser 1 -ErrorAction Stop

Error:

Failed to update maximum devices per user, Error:Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException: user_interaction_required: One of two conditions was encountered: 1.
The PromptBehavior.Never flag was passed, but the constraint could not be honored, because user interaction was required. 2. An error occurred during a silent web authentication tha
t prevented the http authentication flow from completing in a short enough time frame
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform.WebUI.<AcquireAuthorizationAsync>d__20.MoveNext() in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirec
tory\Platforms\net45\WebUI.cs:line 102
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenInteractiveHandler.<AcquireAuthorizationAsync>d__15.MoveNext() in D:\a\1\s\src\Microsoft.IdentityMod
el.Clients.ActiveDirectory\Internal\Flows\AcquireTokenInteractiveHandler.cs:line 178
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenInteractiveHandler.<PreTokenRequestAsync>d__14.MoveNext() in D:\a\1\s\src\Microsoft.IdentityModel.Cl
ients.ActiveDirectory\Internal\Flows\AcquireTokenInteractiveHandler.cs:line 165
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.<RunAsync>d__60.MoveNext() in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirecto
ry\Internal\Flows\AcquireTokenHandlerBase.cs:line 241
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenCommonAsync>d__42.MoveNext() in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory
\AuthenticationContext.cs:line 608
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenAsync>d__34.MoveNext() in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\Authe
nticationContext.cs:line 442
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Online.Administration.Automation.CommonFiles.AuthManager.GetAdrsAuthenticationHeader() in X:\bt\1225946\repo\src\dev\PowerShell.V1\modules\psmodule\CommonFiles\AuthM
anager.cs:line 244
at Microsoft.Online.Administration.Automation.SetDeviceRegistrationServicePolicy.ProcessRecord() in X:\bt\1225946\repo\src\dev\PowerShell.V1\modules\psmodule\Cmdlets\DeviceRegist
rationServiceCmdlets.cs:line 224
ErrorCode: user_interaction_required

It was working a week ago but now we are facing this error.

Kindly help on resolving this.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Sandeep G-MSFT 20,926 Reputation points Microsoft Employee Moderator
    2022-10-06T03:10:33.183+00:00

    @Krupa Gundraju (Larsen & Toubro Infotech Limit)

    As mentioned above you will have to set " Devices | Device settings | Require Multi-Factor Authentication to register or join devices with Azure AD" to "No" to fix this issue.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Vasil Michev 119.9K Reputation points MVP Volunteer Moderator
    2022-10-03T13:28:33.223+00:00

    This looks like an authentication issue, and likely because MFA is required. Instead of passing credentials, try connecting via Connect-MsolService without providing any parameters.

    In any case, as the MSOnline module is on a deprecation path, consider using the Graph API instead to update the policy: https://learn.microsoft.com/en-us/graph/api/resources/deviceregistrationpolicy?view=graph-rest-beta&viewFallbackFrom=graph-rest-1.0


  2. Krupa Gundraju (Larsen & Toubro Infotech Limit) 126 Reputation points
    2022-10-04T12:32:34.693+00:00

    The issue here was with Devices | Device settings | Require Multi-Factor Authentication to register or join devices with Azure AD. post setting this to 'no' it is working as expected.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.