title: How to assign Tags to all VMs only in a resource group using Azure cli
body: <p>I am trying to write an Azure CLI script that logs me into the portal using service principal, selects the subscription and then tag VMs in that subscription per Resource group only.</p>
  
  <pre><code>az login -u $service_principal_ID -p $service_principal_password --service-principal --tenant $tenant_ID
  
  az account set --subscription $subID
  
  az resource tag --resource-group $rg \
  --tags tags.project=$project tags.owner=$owner tags.environment=$env \
  --resource-type "Microsoft.Compute/virtualMachines" \
  --output tsv
  </code></pre>
  
  <p>Azure gives me error when running this saying <code>--name</code> is missing, but I don't want to tag the VMs one by one.</p>
  
  <p>Any Ideas?</p>