az vm identity

Manage service identities of a VM.

Commands

az vm identity assign Enable managed service identity on a VM.
az vm identity remove Remove managed service identities from a VM.
az vm identity show Display VM's managed identity info.

az vm identity assign

Enable managed service identity on a VM.

az vm identity assign [--identities]
[--ids]
[--name]
[--resource-group]
[--role]
[--scope]
[--subscription]

Examples

Enable the system assigned identity on a VM with the 'Reader' role.

az vm identity assign -g MyResourceGroup -n MyVm --role Reader --scope /subscriptions/db5eb68e-73e2-4fa8-b18a-0123456789999/resourceGroups/MyResourceGroup

Enable the system assigned identity and a user assigned identity on a VM.

az vm identity assign -g MyResourceGroup -n MyVm --role Reader --identities [system] myAssignedId

Optional Parameters

--identities

Space-separated identities to assign. Use '[system]' to refer to the system assigned identity. Default: '[system]'.

--ids

One or more resource IDs (space-delimited). If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--role

Role name or id the system assigned identity will have.

default value: Contributor
--scope

Scope that the system assigned identity can access.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm identity remove

Remove managed service identities from a VM.

az vm identity remove [--identities]
[--ids]
[--name]
[--resource-group]
[--subscription]

Examples

Remove the system assigned identity

az vm identity remove -g MyResourceGroup -n MyVm

Remove a user assigned identity

az vm identity remove -g MyResourceGroup -n MyVm --identities readerId

Remove 2 identities which are in the same resource group with the VM

az vm identity remove -g MyResourceGroup -n MyVm --identities readerId writerId

Remove the system assigned identity and a user identity

az vm identity remove -g MyResourceGroup -n MyVm --identities [system] readerId

Optional Parameters

--identities

Space-separated identities to remove. Use '[system]' to refer to the system assigned identity. Default: '[system]'.

--ids

One or more resource IDs (space-delimited). If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vm identity show

Display VM's managed identity info.

az vm identity show [--ids]
[--name]
[--resource-group]
[--subscription]

Examples

display VM's managed identity info. (autogenerated)

az vm identity show --name MyVirtualMachine --resource-group MyResourceGroup

Optional Parameters

--ids

One or more resource IDs (space-delimited). If provided, no other 'Resource Id' arguments should be specified.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.