az resource

Manage Azure resources.

Commands

az resource create Create a resource.
az resource delete Delete a resource.
az resource invoke-action Invoke an action on the resource.
az resource link Manage links between resources.
az resource link create Create a new link between resources.
az resource link delete Delete a link between resources.
az resource link list List resource links.
az resource link show Get details for a resource link.
az resource link update Update link between resources.
az resource list List resources.
az resource lock Manage Azure resource level locks.
az resource lock create Create a resource-level lock.
az resource lock delete Delete a resource-level lock.
az resource lock list List lock information in the resource-level.
az resource lock show Show the details of a resource-level lock.
az resource lock update Update a resource-level lock.
az resource move Moves resources from one resource group to another(can be under different subscription).
az resource show Get the details of a resource.
az resource tag Tag a resource.
az resource update Update a resource.

az resource create

Create a resource.

az resource create --properties
[--api-version]
[--id]
[--is-full-object]
[--location]
[--name]
[--namespace]
[--parent]
[--resource-group]
[--resource-type]

Examples

Create an API app by providing a full JSON configuration.

az resource create -g myRG -n myApiApp --resource-type Microsoft.web/sites --is-full-object --properties         '{            "kind": "api",            "location": "West US",            "properties": {                "serverFarmId": "/subscriptions/{SubID}/resourcegroups/{MyRG}/providers/Microsoft.Web/serverfarms/{MyServicePlan}"            }        }'

Create a resource by loading JSON configuration from a file.

az resource create -g myRG -n myApiApp --resource-type Microsoft.web/sites --is-full-object --properties @jsonConfigFile

Create a web app with the minimum required configuration information.

az resource create -g myRG -n myWeb --resource-type Microsoft.web/sites --properties     {         "serverFarmId":"/subscriptions/{SubID}/resourcegroups/{MyRG}/providers/Microsoft.Web/serverfarms/{MyServicePlan}"     }

Required Parameters

--properties -p

A JSON-formatted string containing resource properties.

Optional Parameters

--api-version

The api version of the resource (omit for latest).

--id

Resource ID.

--is-full-object

Indicates that the properties object includes other options such as location, tags, sku, and/or plan.

--location -l

Location. You can configure the default location using az configure --defaults location=<location>.

--name -n

The resource name. (Ex: myC).

--namespace

Provider namespace (Ex: 'Microsoft.Provider').

--parent

The parent path (Ex: 'resA/myA/resB/myB').

--resource-group -g

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

--resource-type

The resource type (Ex: 'resC'). Can also accept namespace/type format (Ex: 'Microsoft.Provider/resC').

az resource delete

Delete a resource.

az resource delete [--api-version]
[--ids]
[--name]
[--namespace]
[--parent]
[--resource-group]
[--resource-type]

Examples

Delete a virtual machine named 'MyVm'.

az vm delete -g MyResourceGroup -n MyVm --resource-type "Microsoft.Compute/virtualMachines"

Delete a web app using a resource identifier.

az resource delete --ids /subscriptions/0b1f6471-1bf0-4dda-aec3-111111111111/resourceGroups/MyResourceGroup/providers/Microsoft.Web/sites/MyWebapp

Delete a subnet using a resource identifier.

az resource delete --ids /subscriptions/0b1f6471-1bf0-4dda-aec3-111111111111/resourceGroups/MyResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/MySubnet

Optional Parameters

--api-version

The api version of the resource (omit for latest).

--ids

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

--name -n

The resource name. (Ex: myC).

--namespace

Provider namespace (Ex: 'Microsoft.Provider').

--parent

The parent path (Ex: 'resA/myA/resB/myB').

--resource-group -g

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

--resource-type

The resource type (Ex: 'resC'). Can also accept namespace/type format (Ex: 'Microsoft.Provider/resC').

az resource invoke-action

Invoke an action on the resource.

A list of possible actions corresponding to a resource can be found at https://docs.microsoft.com/en-us/rest/api/. All POST requests are actions that can be invoked and are specified at the end of the URI path. For instance, to stop a VM, the request URI is https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm}/powerOff?api-version={apiVersion} and the corresponding action is powerOff. This can be found at https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-stop.

az resource invoke-action --action
[--api-version]
[--ids]
[--name]
[--namespace]
[--parent]
[--request-body]
[--resource-group]
[--resource-type]

Examples

Power-off a vm, specified by Id.

az resource invoke-action --action powerOff --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM

Capture information for a stopped vm.

az resource invoke-action --action capture --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM --request-body {"vhdPrefix":"myPrefix","destinationContainerName":"myContainer","overwriteVhds":"true"}

Required Parameters

--action

The action that will be invoked on the specified resource.

Optional Parameters

--api-version

The api version of the resource (omit for latest).

--ids

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

--name -n

The resource name. (Ex: myC).

--namespace

Provider namespace (Ex: 'Microsoft.Provider').

--parent

The parent path (Ex: 'resA/myA/resB/myB').

--request-body

JSON encoded parameter arguments for the action that will be passed along in the post request body. Use @{file} to load from a file.

--resource-group -g

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

--resource-type

The resource type (Ex: 'resC'). Can also accept namespace/type format (Ex: 'Microsoft.Provider/resC').

az resource list

List resources.

az resource list [--location]
[--name]
[--namespace]
[--resource-group]
[--resource-type]
[--tag]

Examples

List all resources in the West US region.

az resource list --location westus

List all resources with the name 'resourceName'.

az resource list --name 'resourceName'

List all resources with the tag 'test'.

az resource list --tag test

List all resources with a tag that starts with 'test'.

az resource list --tag test*

List all resources with the tag 'test' that have the value 'example'.

az resource list --tag test=example

Optional Parameters

--location -l

Location. You can configure the default location using az configure --defaults location=<location>.

--name -n

The resource name. (Ex: myC).

--namespace

Provider namespace (Ex: 'Microsoft.Provider').

--resource-group -g

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

--resource-type

The resource type (Ex: 'resC'). Can also accept namespace/type format (Ex: 'Microsoft.Provider/resC').

--tag

A single tag in 'key[=value]' format. Use "" to clear existing tags.

az resource move

Moves resources from one resource group to another(can be under different subscription).

az resource move --destination-group
--ids
[--destination-subscription-id]

Required Parameters

--destination-group

The destination resource group name.

--ids

The space separated resource ids to be moved.

Optional Parameters

--destination-subscription-id

The destination subscription identifier.

az resource show

Get the details of a resource.

az resource show [--api-version]
[--ids]
[--name]
[--namespace]
[--parent]
[--resource-group]
[--resource-type]

Examples

Show a virtual machine resource named 'MyVm'.

az vm show -g MyResourceGroup -n MyVm --resource-type "Microsoft.Compute/virtualMachines"

Show a web app using a resource identifier.

az resource show --ids /subscriptions/0b1f6471-1bf0-4dda-aec3-111111111111/resourceGroups/MyResourceGroup/providers/Microsoft.Web/sites/MyWebapp

Show a subnet.

az resource show -g MyResourceGroup -n MySubnet --namespace Microsoft.Network --parent virtualnetworks/MyVnet --resource-type subnets

Show a subnet using a resource identifier.

az resource show --ids /subscriptions/0b1f6471-1bf0-4dda-aec3-111111111111/resourceGroups/MyResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/MySubnet

Show an application gateway path rule.

az resource show -g MyResourceGroup --namespace Microsoft.Network --parent applicationGateways/ag1/urlPathMaps/map1 --resource-type pathRules -n rule1

Optional Parameters

--api-version

The api version of the resource (omit for latest).

--ids

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

--name -n

The resource name. (Ex: myC).

--namespace

Provider namespace (Ex: 'Microsoft.Provider').

--parent

The parent path (Ex: 'resA/myA/resB/myB').

--resource-group -g

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

--resource-type

The resource type (Ex: 'resC'). Can also accept namespace/type format (Ex: 'Microsoft.Provider/resC').

az resource tag

Tag a resource.

az resource tag --tags
[--api-version]
[--ids]
[--name]
[--namespace]
[--parent]
[--resource-group]
[--resource-type]

Examples

Tag the virtual machine 'MyVm' with the key 'vmlist' and value 'vm1'.

az resource tag --tags vmlist=vm1 -g MyResourceGroup -n MyVm --resource-type "Microsoft.Compute/virtualMachines"

Tag a web app with the key 'vmlist' and value 'vm1', using a resource identifier.

az resource tag --tags vmlist=vm1 --id /subscriptions/{SubID}/resourceGroups/{MyRG}/providers/Microsoft.Web/sites/{MyWebApp}

Required Parameters

--tags

Space separated tags in 'key[=value]' format. Use "" to clear existing tags.

Optional Parameters

--api-version

The api version of the resource (omit for latest).

--ids

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

--name -n

The resource name. (Ex: myC).

--namespace

Provider namespace (Ex: 'Microsoft.Provider').

--parent

The parent path (Ex: 'resA/myA/resB/myB').

--resource-group -g

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

--resource-type

The resource type (Ex: 'resC'). Can also accept namespace/type format (Ex: 'Microsoft.Provider/resC').

az resource update

Update a resource.

az resource update [--add]
[--api-version]
[--ids]
[--name]
[--namespace]
[--parent]
[--remove]
[--resource-group]
[--resource-type]
[--set]

Optional Parameters

--add

Add an object to a list of objects by specifying a path and key value pairs. Example: --add property.listProperty <key=value, string or JSON string>.

--api-version

The api version of the resource (omit for latest).

--ids

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

--name -n

The resource name. (Ex: myC).

--namespace

Provider namespace (Ex: 'Microsoft.Provider').

--parent

The parent path (Ex: 'resA/myA/resB/myB').

--remove

Remove a property or an element from a list. Example: --remove property.list OR --remove propertyToRemove.

--resource-group -g

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

--resource-type

The resource type (Ex: 'resC'). Can also accept namespace/type format (Ex: 'Microsoft.Provider/resC').

--set

Update an object by specifying a property path and value to set. Example: --set property1.property2=.