'Azure Automation Account runbook error while remove/add user role on the storage account

When i'm trying to remove user on the storage account using below commands through automation account i'm getting error

object reference not set to instance of an object

Remove-AzRoleAssignment -SignInName $emailid -RoleDefinitionName 
"Storage File Data SMB Share Contributor" -Scope "/subscriptions/00000-0000-00/resourceGroups/resourcegroupname/providers/Microsoft.Storage/storageAccounts/storageaccname"

enter image description here



Solution 1:[1]

Few of the workaround you can follow to achieve the above requirement;

  • Make sure that you have following permission to that subscription Owner or, User Access Administrator( must have a role that includes Microsoft.Authorization/roleAssignments/write permissions) to assign or remove.

  • If you have above permission Check the role which have defined in storage account same as what you have mentioned want to remove. Or it exist or not.

  • And make sure that the role which you want to remove, that not showing as inherited If so you can not remove those assignments as you are trying to remove a role assignment at a child scope.

For more information please refer the below links:-

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AjayKumarGhose-MT