|
1 | 1 | ---
|
2 | 2 | title: Advanced query samples
|
3 | 3 | description: Use Azure Resource Graph to run some advanced queries, including working with columns, listing tags used, and matching resources with regular expressions.
|
4 |
| -ms.date: 12/02/2019 |
| 4 | +ms.date: 12/05/2019 |
5 | 5 | ms.topic: sample
|
6 | 6 | ---
|
7 | 7 | # Advanced Resource Graph query samples
|
@@ -396,7 +396,45 @@ Search-AzGraph -Query "Resources | where type =~ 'microsoft.compute/virtualmachi
|
396 | 396 | ## <a name="join-findstoragetag" />Find storage accounts with a specific tag on the resource group
|
397 | 397 |
|
398 | 398 | The following query uses an **inner** `join` to connect storage accounts with resource groups that
|
399 |
| -have a specified case insensitive tag name and tag value. |
| 399 | +have a specified case sensitive tag name and tag value. |
| 400 | + |
| 401 | +```kusto |
| 402 | +Resources |
| 403 | +| where type =~ 'microsoft.storage/storageaccounts' |
| 404 | +| join kind=inner ( |
| 405 | + ResourceContainers |
| 406 | + | where type =~ 'microsoft.resources/subscriptions/resourcegroups' |
| 407 | + | where tags['Key1'] =~ 'Value1' |
| 408 | + | project subscriptionId, resourceGroup) |
| 409 | +on subscriptionId, resourceGroup |
| 410 | +| project-away subscriptionId1, resourceGroup1 |
| 411 | +``` |
| 412 | + |
| 413 | +# [Azure CLI](#tab/azure-cli) |
| 414 | + |
| 415 | +```azurecli-interactive |
| 416 | +az graph query -q "Resources | where type =~ 'microsoft.storage/storageaccounts' | join kind=inner ( ResourceContainers | where type =~ 'microsoft.resources/subscriptions/resourcegroups' | where tags['Key1'] =~ 'Value1' | project subscriptionId, resourceGroup) on subscriptionId, resourceGroup | project-away subscriptionId1, resourceGroup1" |
| 417 | +``` |
| 418 | + |
| 419 | +# [Azure PowerShell](#tab/azure-powershell) |
| 420 | + |
| 421 | +```azurepowershell-interactive |
| 422 | +Search-AzGraph -Query "Resources | where type =~ 'microsoft.storage/storageaccounts' | join kind=inner ( ResourceContainers | where type =~ 'microsoft.resources/subscriptions/resourcegroups' | where tags['Key1'] =~ 'Value1' | project subscriptionId, resourceGroup) on subscriptionId, resourceGroup | project-away subscriptionId1, resourceGroup1" |
| 423 | +``` |
| 424 | + |
| 425 | +# [Portal](#tab/azure-portal) |
| 426 | + |
| 427 | + Try this query in Azure Resource Graph Explorer: |
| 428 | + |
| 429 | +- Azure portal: <a href="https://portal.azure.com/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/Resources%20%7C%20where%20type%20%3D~%20'microsoft.storage%2Fstorageaccounts'%20%7C%20join%20kind%3Dinner%20(%20ResourceContainers%20%7C%20where%20type%20%3D~%20'microsoft.resources%2Fsubscriptions%2Fresourcegroups'%20%7C%20where%20tags%5B'Key1'%5D%20%3D~%20'Value1'%20%7C%20project%20subscriptionId%2C%20resourceGroup)%20on%20subscriptionId%2C%20resourceGroup%20%7C%20project-away%20subscriptionId1%2C%20resourceGroup1" target="_blank">portal.azure.com</a>  |
| 430 | +- Azure Government portal: <a href="https://portal.azure.us/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/Resources%20%7C%20where%20type%20%3D~%20'microsoft.storage%2Fstorageaccounts'%20%7C%20join%20kind%3Dinner%20(%20ResourceContainers%20%7C%20where%20type%20%3D~%20'microsoft.resources%2Fsubscriptions%2Fresourcegroups'%20%7C%20where%20tags%5B'Key1'%5D%20%3D~%20'Value1'%20%7C%20project%20subscriptionId%2C%20resourceGroup)%20on%20subscriptionId%2C%20resourceGroup%20%7C%20project-away%20subscriptionId1%2C%20resourceGroup1" target="_blank">portal.azure.us</a>  |
| 431 | +- Azure China portal: <a href="https://portal.azure.cn/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/Resources%20%7C%20where%20type%20%3D~%20'microsoft.storage%2Fstorageaccounts'%20%7C%20join%20kind%3Dinner%20(%20ResourceContainers%20%7C%20where%20type%20%3D~%20'microsoft.resources%2Fsubscriptions%2Fresourcegroups'%20%7C%20where%20tags%5B'Key1'%5D%20%3D~%20'Value1'%20%7C%20project%20subscriptionId%2C%20resourceGroup)%20on%20subscriptionId%2C%20resourceGroup%20%7C%20project-away%20subscriptionId1%2C%20resourceGroup1" target="_blank">portal.azure.cn</a>  |
| 432 | + |
| 433 | +--- |
| 434 | + |
| 435 | +If it's necessary to look for a case insensitive tag name and tag value, use `mvexpand` with the |
| 436 | +**bagexpansion** parameter. This query uses more quota than the previous query, so use `mvexpand` |
| 437 | +only if necessary. |
400 | 438 |
|
401 | 439 | ```kusto
|
402 | 440 | Resources
|
|
0 commit comments