Getting invalid status code conflict while running New-AzRoleAssignment in powershell, same setup works in another server

Abhishek Singh 381 Reputation points
2021-12-03T11:20:06.65+00:00

I am trying to run the below cmdlet in PowerShell and ending up in error : Operation returned invalid status code conflict

New-AzRoleAssignment -ObjectID "" -RoleDefinationName "" -Scope ""

same setup works fine in another server , but breaks in different server below are the modules installed and versions:

Az : 6.6
Az.Resources : 4.4.1

Unable to figure out why it breaks in one server but works fine in another

Windows for business Windows Server User experience PowerShell
Microsoft Security Microsoft Entra Microsoft Entra ID
{count} vote

Accepted answer
  1. Siva-kumar-selvaraj 15,721 Reputation points
    2021-12-03T19:29:05.973+00:00

    Hello @Abhishek Singh ,

    Thanks for reaching out.

    You may receive New-AzRoleAssignment: Operation returned an incorrect status code 'Conflict' if a certain user object is already assigned with the same role, hence, I would recommend you to ensure that the role assignment doesn't exists already. Additionally, make sure that there are no additional spaces in the value supplied in parameters such as ObjectId, RoleDefinitionName, and scope.

    If the same issue persists, you could use the -Verbose -Debug parameter which would help you to get further insight from the body message of the HTTP RESPONSE, as seen below:

    Debug Cmdlet:
    New-AzRoleAssignment -ObjectId $id -RoleDefinitionName $role -Scope $scope -Verbose -Debug

    Debug Response:
    154810-image.png

    **Note: **
    There is upcoming breaking changes in the cmdlet "New-AzRoleAssignment" from "Az.Resources 4.4.1" as this cmdlet will migrated to use Microsoft Graph in Az 7.x and later. Therefore, try using the Az.Resources PowerShell module version 5.0.0-preview to see if the same issue persist.

    Cmdlet to install preview: Install-Module -Name Az.Resources -Repository PSGallery -Scope CurrentUser -AllowPrerelease and uninstall Uninstall-Module Az.Resources -AllowPrerelease

    Refer, https://go.microsoft.com/fwlink/?linkid=2174792 for migration guide and breaking changes.

    I hope this was helpful.

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

    5 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.