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 Gets a resource link with the specified ID.
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 wait Place the CLI in a waiting state until a condition of a resources is met.

az resource create

Create a resource.

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

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/{ResourceGroup}/providers/Microsoft.Web/serverfarms/{ServicePlan}"
                                    }
                                }'

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/{ResourceGroup}/providers/Microsoft.Web/serverfarms/{ServicePlan}"
                            }'

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. Values from: az account list-locations. 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').

--subscription

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

az resource delete

Delete a resource.

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

Examples

Delete a virtual machine named 'MyVm'.

az resource 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').

--subscription

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

az resource invoke-action

Invoke an action on the resource.

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

Examples

Power-off a vm, specified by Id.

az resource invoke-action --action powerOff \
                          --ids /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.Compute/virtualMachines/{VMName}

Capture information for a stopped vm.

az resource invoke-action --action capture \
                          --ids /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.Compute/virtualMachines/{VMName} \
                          --request-body '{
                            "vhdPrefix": "myPrefix",
                            "destinationContainerName": "myContainer",
                            "overwriteVhds": true
                        }'

Invoke an action on the resource. (autogenerated)

az resource invoke-action --action capture --name MyResource --resource-group MyResourceGroup --resource-type Microsoft.web/sites

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').

--subscription

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

az resource list

List resources.

az resource list [--location]
[--name]
[--namespace]
[--resource-group]
[--resource-type]
[--subscription]
[--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. Values from: az account list-locations. 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').

--subscription

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

--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]
[--subscription]

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.

--subscription

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

az resource show

Get the details of a resource.

az resource show [--api-version]
[--ids]
[--include-response-body {false, true}]
[--name]
[--namespace]
[--parent]
[--resource-group]
[--resource-type]
[--subscription]

Examples

Show a virtual machine resource named 'MyVm'.

az resource 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.

--include-response-body

Use if the default command output doesn't capture all of the property data.

accepted values: false, true
--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').

--subscription

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

az resource tag

Tag a resource.

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

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/{ResourceGroup}/providers/Microsoft.Web/sites/{WebApp}

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').

--subscription

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

az resource update

Update a resource.

az resource update [--add]
[--api-version]
[--force-string]
[--ids]
[--include-response-body {false, true}]
[--name]
[--namespace]
[--parent]
[--remove]
[--resource-group]
[--resource-type]
[--set]
[--subscription]

Examples

Update a resource. (autogenerated)

az resource update --ids $id --set properties.connectionType=Proxy

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).

--force-string

When using 'set' or 'add', preserve string literals instead of attempting to convert to JSON.

--ids

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

--include-response-body

Use if the default command output doesn't capture all of the property data.

accepted values: false, true
--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=.

--subscription

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

az resource wait

Place the CLI in a waiting state until a condition of a resources is met.

az resource wait [--api-version]
[--created]
[--custom]
[--deleted]
[--exists]
[--ids]
[--include-response-body {false, true}]
[--interval]
[--name]
[--namespace]
[--parent]
[--resource-group]
[--resource-type]
[--subscription]
[--timeout]
[--updated]

Optional Parameters

--api-version

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

--created

Wait until created with 'provisioningState' at 'Succeeded'.

--custom

Wait until the condition satisfies a custom JMESPath query. E.g. provisioningState!='InProgress', instanceView.statuses[?code=='PowerState/running'].

--deleted

Wait until deleted.

--exists

Wait until the resource exists.

--ids

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

--include-response-body

Use if the default command output doesn't capture all of the property data.

accepted values: false, true
--interval

Polling interval in seconds.

default value: 30
--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').

--subscription

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

--timeout

Maximum wait in seconds.

default value: 3600
--updated

Wait until updated with provisioningState at 'Succeeded'.