You are on page 1of 2

# Login to Azure

az login

#Create resource groups


az group create --name $resourceGroupName --location $location

#List resource groups


az group list

#Delete resource groups


az group delete --name $resourceGroupName

#Create Tags
az resource tag --tags Department=Finance \
--resource-group msftlearn-core-infrastructure-rg \
--name msftlearn-vnet1 \
--resource-type "Microsoft.Network/virtualNetworks"

#To add the tags on a resource, use:


az resource tag --tags 'Dept=IT' 'Environment=Test' -g examplegroup -n examplevnet
--resource-type "Microsoft.Network/virtualNetworks"

#To append a tag to the existing tags on a resource, use:


az resource update --set tags.'Status'='Approved' -g examplegroup -n examplevnet --
resource-type "Microsoft.Network/virtualNetworks“

#To overwrite the existing tags on a resource group, use:


az group update -n examplegroup --tags 'Environment=Test' 'Dept=IT’

#To append a tag to the existing tags on a resource group, use:


az group update -n examplegroup --set tags.'Status'='Approved’

#To see the existing tags for a resource, use:


az resource show -n examplevnet -g examplegroup --resource-type
"Microsoft.Network/virtualNetworks" --query tags

#To see the existing tags for a resource group, use:


az group show -n examplegroup --query tags

#To get all the resources that have a particular tag and value, use az resource
list:
az resource list --tag Dept=Finance

#To get resource groups that have a specific tag, use az group list:
az group list --tag Dept=IT

#Run the following command to create a policy assignment:


az policy assignment create --name 'audit-vm-manageddisks' \
--display-name 'Audit VMs without managed disks Assignment' \
--scope '<scope>' --policy '<policy definition ID>’

#To view the resources that aren't compliant under this new assignment, get the
policy assignment ID by running the following commands:
az policy assignment list --query "[?displayName=='Audit VMs without managed disks
Assignment'].id"

#To remove the assignment created, use the following command:


az policy assignment delete --name 'audit-vm-manageddisks' --scope
'/subscriptions/<subscriptionID>/<resourceGroupName>'

#To lock a resource, provide the name of the resource, its resource type, and its
resource group name.
az lock create --name LockSite --lock-type CanNotDelete --resource-group
exampleresourcegroup --resource-name examplesite --resource-type
Microsoft.Web/sites

#To lock a resource group, provide the name of the resource group.
az lock create --name LockGroup --lock-type CanNotDelete --resource-group
exampleresourcegroup

#To get all locks for a resource, use:


az lock list --resource-group exampleresourcegroup --resource-name examplesite --
namespace Microsoft.Web --resource-type sites --parent "“

#To get all locks for a resource group, use:


az lock list --resource-group exampleresourcegroup

#To delete a lock, use:


lockid=$(az lock show --name LockSite --resource-group exampleresourcegroup --
resource-type Microsoft.Web/sites --resource-name examplesite --output tsv --query
id)
az lock delete --ids $lockid

You might also like