Skip to content

Instantly share code, notes, and snippets.

@kasunkv
Last active March 10, 2019 07:38
Show Gist options
  • Save kasunkv/981c2a6ceaf8b6dcd2a48b2a6cc0d7e7 to your computer and use it in GitHub Desktop.
Save kasunkv/981c2a6ceaf8b6dcd2a48b2a6cc0d7e7 to your computer and use it in GitHub Desktop.
Creating a Policy Assignment using Azure CLI
# Login to Azure
az login --use-device-code
# Get Regerence to Resource Group
$rgId = az group show --name "az-policy-rg" --query "id" --output tsv
# Get Reference to the Azure Policy Definition
$policyName = az policy definition list --query "[?displayName == 'Audit use of classic virtual machines'].name" --output tsv
# Assign the policy
az policy assignment create --name "Check for Classic VMs" --display-name "Check for Classic VMs" --policy $policyName --scope $rgId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment