CmdID / az / az policy / az policy assignment / az policy assignment identity
az policy assignment identity assign
Assign a managed identity. Azure CLI reference
Assign the system or user assigned managed identity to the policy assignment matching the given name and scope.
3 examples 3 options Its page in the Azure CLI reference
Examples
Add a system assigned managed identity to a policy assignment
az policy assignment identity assign --system-assigned -g MyResourceGroup -n MyPolicyAssignmentIdentify--system-assignedSet the system managed identity.-gName of resource group.Add a system assigned managed identity to a policy assignment and grant it the Contributor role for a resource group
az policy assignment identity assign --system-assigned -g MyResourceGroup -n MyPolicyAssignment --role Contributor --identity-scope /subscriptions/{subscriptionId}/resourceGroups/MyResourceGroupIdentify--system-assignedSet the system managed identity.-gName of resource group.Add a user assigned managed identity to a policy assignment
az policy assignment identity assign --user-assigned MyAssignedId -g MyResourceGroup -n MyPolicyAssignmentIdentify--user-assignedSet the user managed identity.-gName of resource group.Options
--mi-system-assigned, --system-assignedSet the system managed identity.--mi-user-assigned, --user-assignedSet the user managed identity.--scope, --name, -n