Skip to content

Commit a51d4db

Browse files
authored
Merge pull request #272949 from davidsmatlak/ds-update-arg-cli-quickstart-20240422
Updates ARG quickstart for CLI
2 parents 1e74a7f + 5173006 commit a51d4db

File tree

5 files changed

+67
-74
lines changed

5 files changed

+67
-74
lines changed

articles/governance/resource-graph/changes/get-resource-changes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ In this article, you learn:
2323
## Prerequisites
2424

2525
- To enable Azure PowerShell to query Azure Resource Graph, [add the module](../first-query-powershell.md#add-the-resource-graph-module).
26-
- To enable Azure CLI to query Azure Resource Graph, [add the extension](../first-query-azurecli.md#add-the-resource-graph-extension).
26+
- To enable Azure CLI to query Azure Resource Graph, [add the extension](../first-query-azurecli.md#install-the-extension).
2727

2828
## Understand change event properties
2929

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,108 @@
11
---
2-
title: "Quickstart: Your first Azure CLI query"
3-
description: In this quickstart, you follow the steps to enable the Resource Graph extension for Azure CLI and run your first query.
4-
ms.date: 08/17/2021
2+
title: "Quickstart: Run Resource Graph query using Azure CLI"
3+
description: In this quickstart, you run an Azure Resource Graph query using the extension for Azure CLI.
4+
ms.date: 04/22/2024
55
ms.topic: quickstart
66
ms.custom: devx-track-azurecli
77
---
8-
# Quickstart: Run your first Resource Graph query using Azure CLI
98

10-
The first step to using Azure Resource Graph is to check that the extension for [Azure
11-
CLI](/cli/azure/) is installed. This quickstart walks you through the process of adding the
12-
extension to your Azure CLI installation. You can use the extension with Azure CLI installed locally
13-
or through the [Azure Cloud Shell](https://shell.azure.com).
9+
# Quickstart: Run Resource Graph query using Azure CLI
1410

15-
At the end of this process, you'll have added the extension to your Azure CLI installation of choice
16-
and run your first Resource Graph query.
11+
This quickstart describes how to run an Azure Resource Graph query using the extension for Azure CLI. The article also shows how to order (sort) and limit the query's results. You can run a query for resources in your tenant, management groups, or subscriptions. When you're finished, you can remove the extension.
1712

1813
## Prerequisites
1914

20-
If you don't have an Azure subscription, create a [free](https://azure.microsoft.com/free/) account
21-
before you begin.
15+
- If you don't have an Azure account, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
16+
- [Azure CLI](/cli/azure/install-azure-cli) must be version 2.22.0 or higher for the Resource Graph extension.
17+
- [Visual Studio Code](https://code.visualstudio.com/).
2218

23-
<!-- [!INCLUDE [cloud-shell-try-it.md](../../../includes/cloud-shell-try-it.md)] -->
19+
## Connect to Azure
2420

25-
## Add the Resource Graph extension
21+
From a Visual Studio Code terminal session, connect to Azure. If you have more than one subscription, run the commands to set context to your subscription. Replace `<subscriptionID>` with your Azure subscription ID.
2622

27-
To enable Azure CLI to query Azure Resource Graph, the extension must be added. This extension
28-
works wherever Azure CLI can be used, including [bash on Windows 10](/windows/wsl/install-win10),
29-
[Cloud Shell](https://shell.azure.com) (both standalone and inside the portal), the [Azure CLI
30-
Docker image](https://hub.docker.com/_/microsoft-azure-cli), or locally installed.
23+
```azurecli
24+
az login
25+
26+
# Run these commands if you have multiple subscriptions
27+
az account list --output table
28+
az account set --subscription <subscriptionID>
29+
```
3130

32-
1. Check that the latest Azure CLI is installed (at least **2.0.76**). If it isn't yet installed,
33-
follow [these instructions](/cli/azure/install-azure-cli-windows).
31+
## Install the extension
3432

35-
1. In your Azure CLI environment of choice, import it with the following command:
33+
To enable Azure CLI to query resources using Azure Resource Graph, the Resource Graph extension must be installed. You can manually install the extension with the following steps. Otherwise, the first time you run a query with `az graph` you're prompted to install the extension.
34+
35+
1. List the available extensions and versions:
36+
37+
```azurecli
38+
az extension list-available --output table
39+
```
40+
41+
1. Install the extension:
3642

3743
```azurecli
38-
# Add the Resource Graph extension to the Azure CLI environment
3944
az extension add --name resource-graph
4045
```
4146

42-
1. Validate that the extension has been installed and is the expected version (at least **1.0.0**):
47+
1. Verify the extension was installed:
4348

4449
```azurecli
45-
# Check the extension list (note that you may have other extensions installed)
46-
az extension list
50+
az extension list --output table
51+
```
4752

48-
# Run help for graph query options
49-
az graph query -h
53+
1. Display the extension's syntax:
54+
55+
```azurecli
56+
az graph query --help
5057
```
5158

52-
## Run your first Resource Graph query
59+
For more information about Azure CLI extensions, go to [Use and manage extensions with the Azure CLI](/cli/azure/azure-cli-extensions-overview).
5360

54-
With the Azure CLI extension added to your environment of choice, it's time to try out a simple
55-
tenant-based Resource Graph query. The query returns the first five Azure resources with the
56-
**Name** and **Resource Type** of each resource. To query by
57-
[management group](../management-groups/overview.md) or subscription, use the `--managementgroups`
58-
or `--subscriptions` arguments.
61+
## Run a query
5962

60-
1. Run your first Azure Resource Graph query using the `graph` extension and `query` command:
63+
After the Azure CLI extension is added to your environment, you can run a tenant-based query. The query in this example returns five Azure resources with the `name` and `type` of each resource. To query by [management group](../management-groups/overview.md) or subscription, use the `--management-groups` or `--subscriptions` arguments.
6164

62-
```azurecli
63-
# Login first with az login if not using Cloud Shell
65+
1. Run an Azure Resource Graph query:
6466

65-
# Run Azure Resource Graph query
66-
az graph query -q 'Resources | project name, type | limit 5'
67+
```azurecli
68+
az graph query --graph-query 'Resources | project name, type | limit 5'
6769
```
6870

69-
> [!NOTE]
70-
> As this query example does not provide a sort modifier such as `order by`, running this query
71-
> multiple times is likely to yield a different set of resources per request.
71+
This query example doesn't use a sort modifier like `order by`. If you run the query multiple times, it might yield a different set of resources for each request.
7272

73-
1. Update the query to `order by` the **Name** property:
73+
1. Update the query to `order by` the `name` property:
7474

7575
```azurecli
76-
# Run Azure Resource Graph query with 'order by'
77-
az graph query -q 'Resources | project name, type | limit 5 | order by name asc'
76+
az graph query --graph-query 'Resources | project name, type | limit 5 | order by name asc'
7877
```
7978

80-
> [!NOTE]
81-
> Just as with the first query, running this query multiple times is likely to yield a different
82-
> set of resources per request. The order of the query commands is important. In this example,
83-
> the `order by` comes after the `limit`. This command order first limits the query results and
84-
> then orders them.
79+
Like the previous query, if you run this query multiple times it might yield a different set of resources for each request. The order of the query commands is important. In this example, the `order by` comes after the `limit`. The query limits the results to five resources and then orders those results by name.
8580

86-
1. Update the query to first `order by` the **Name** property and then `limit` to the top five
87-
results:
81+
1. Update the query to `order by` the `name` property and then `limit` the output to five results:
8882

8983
```azurecli
90-
# Run Azure Resource Graph query with `order by` first, then with `limit`
91-
az graph query -q 'Resources | project name, type | order by name asc | limit 5'
84+
az graph query --graph-query 'Resources | project name, type | order by name asc | limit 5'
9285
```
9386

94-
When the final query is run several times, assuming that nothing in your environment is changing,
95-
the results returned are consistent and ordered by the **Name** property, but still limited to the
96-
top five results.
87+
If this query is run several times with no changes to your environment, the results are consistent and ordered by the `name` property, but still limited to five results. The query orders the results by name and then limits the output to five resources.
9788

9889
## Clean up resources
9990

100-
If you wish to remove the Resource Graph extension from your Azure CLI environment, you can do so by
101-
using the following command:
91+
To remove the Resource Graph extension, run the following command:
92+
93+
```azurecli
94+
az extension remove --name resource-graph
95+
```
96+
97+
To sign out of your Azure CLI session:
10298

10399
```azurecli
104-
# Remove the Resource Graph extension from the Azure CLI environment
105-
az extension remove -n resource-graph
100+
az logout
106101
```
107102

108103
## Next steps
109104

110-
In this quickstart, you've added the Resource Graph extension to your Azure CLI environment and run
111-
your first query. To learn more about the Resource Graph language, continue to the query language
112-
details page.
105+
In this quickstart, you ran Azure Resource Graph queries using the extension for Azure CLI. To learn more, go to the query language details article.
113106

114107
> [!div class="nextstepaction"]
115-
> [Get more information about the query language](./concepts/query-language.md)
108+
> [Understanding the Azure Resource Graph query language](./concepts/query-language.md)

articles/governance/resource-graph/samples/advanced.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ before you begin.
3737

3838
Azure CLI (through an extension) and Azure PowerShell (through a module) support Azure Resource
3939
Graph. Before running any of the following queries, check that your environment is ready. See
40-
[Azure CLI](../first-query-azurecli.md#add-the-resource-graph-extension) and [Azure
40+
[Azure CLI](../first-query-azurecli.md#install-the-extension) and [Azure
4141
PowerShell](../first-query-powershell.md#add-the-resource-graph-module) for steps to install and
4242
validate your shell environment of choice.
4343

articles/governance/resource-graph/samples/starter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ before you begin.
4141

4242
Azure CLI (through an extension) and Azure PowerShell (through a module) support Azure Resource
4343
Graph. Before running any of the following queries, check that your environment is ready. See
44-
[Azure CLI](../first-query-azurecli.md#add-the-resource-graph-extension) and [Azure
44+
[Azure CLI](../first-query-azurecli.md#install-the-extension) and [Azure
4545
PowerShell](../first-query-powershell.md#add-the-resource-graph-module) for steps to install and
4646
validate your shell environment of choice.
4747

articles/governance/resource-graph/toc.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
- name: Quickstarts
99
expanded: true
1010
items:
11-
- name: Run your first query - Portal
12-
displayName: portal, resource, graph, explorer
11+
- name: Run a query - Azure portal
12+
displayName: portal, resource, az graph, explorer
1313
href: ./first-query-portal.md
14-
- name: Run your first query - Azure CLI
15-
displayName: extension, docker
14+
- name: Run a query - Azure CLI
15+
displayName: extension, docker, resource, graph, explorer
1616
href: ./first-query-azurecli.md
17-
- name: Run your first query - Azure PowerShell
17+
- name: Run a query - Azure PowerShell
1818
displayName: module, docker, Az.ResourceGraph
1919
href: ./first-query-powershell.md
20-
- name: Run your first query - REST
21-
displayName: armclient, postman
20+
- name: Run a query - REST
21+
displayName: az rest
2222
href: ./first-query-rest-api.md
2323
- name: Create a shared query - Azure CLI
2424
displayName: extension, docker, queries

0 commit comments

Comments
 (0)