Login and default subscription
- Login:
az login(Connect-AzAccount) - List subscriptions:
az account list --output table - Set default subscription:
az account set --subscription "subscription name or Id"(Set-AzContext -SubscriptionId "suscription Id") - Delete a web app:
az webapp delete --name MyWebapp --resource-group MyResourceGroup
Tags
- Get list of tags for a resource group:
az group show -n <resource group name> --query tags - Get tags for a specific resource type:
az resource show -n <resource name> -g <resource group name> --resource-type "Microsoft.Network/virtualNetworks" --query tags - Get resources with specific tag name and value:
az resource list --tag Dept=FinanceThis won’t return resource groups - to list resource groups useaz group list --tag Dept=Finance - To add tags to a resource that already has tags (just adding will overwrite existing):
$jsonrtag=$(az resource show -g examplegroup -n examplevnet --resource-type "Microsoft.Network/virtualNetworks" --query tags) $rt=$(echo $jsonrtag | tr -d '"{},' | sed 's/: /=/g') az resource tag --tags $rt Project=Redesign -g examplegroup -n examplevnet --resource-type "Microsoft.Network/virtualNetworks"
RBAC
- Create custom role:
1.Create json file RBAC_Create_Custom_Role.json with:
json { "Name": "Network Resource Viewer", "IsCustom": true, "Description": "Allows reading Azure network resources", "Actions": [ "Microsoft.Network/*/read" ], "NotActions": [ ], "AssignableScopes": [ "/subscriptions/f57fa698-4903-468c-b000-9f935e4de44a" ] }2. Run cli command:az role definition create --role-definition RBAC_Create_Custom_Role.json - List custom roles
az role definition list --custom-role-only true | find "roleName"