Skip to content

Instantly share code, notes, and snippets.

@kasunkv
Created March 10, 2019 07:28
Show Gist options
  • Save kasunkv/1092abdaea4a1d856719310854638527 to your computer and use it in GitHub Desktop.
Save kasunkv/1092abdaea4a1d856719310854638527 to your computer and use it in GitHub Desktop.
Create Azure Policy Assignment using Azure PowerShell
# Login to Azure Subscription
Login-AzureRmAccount
# Get a reference to the resource group
$rg = Get-AzureRmResourceGroup -Name "az-policy-rg"
# Get a referecen to the Azure Policy Definition
$policyDef = Get-AzureRmPolicyDefinition | Where-Object { $_.Properties.DisplayName -eq "Audit VMs that do not use managed disks" }
# Create the new Policy Assignment for the Resource Group
New-AzureRmPolicyAssignment -Name "Check for Managerd Disks" -DisplayName "Check for Managed Disks" -Scope $rg.ResourceId -PolicyDefinition $policyDef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment