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:
**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.