Skip to content

Policy

SYNOPSIS

Declares one Azure Policy definition.

SYNTAX

Policy [-Name] <String> [-Body] <ScriptBlock> [<CommonParameters>]

DESCRIPTION

A top-level block of a .bylaw.ps1 file, like Initiative. The scriptblock describes the compliant state of a resource using the inner keywords (Properties, Parameter, Resource, When, Require, Each, AnyOf, AllOf, Field, Element, Tag, ResourceGroupTag, Must, Effect, Modify, AddOrReplace, Add, Remove, Append, DenyAction, Manual, AuditIfNotExists, DeployIfNotExists, Deployment, Count, Current, Param, Arm), which exist only while the block runs.

Errors inside the block are recorded as diagnostics with file, line and keyword, and are reported together by Build-Bylaw.

USED IN

The top level of a .bylaw.ps1 file

EXAMPLES

Example 1

Policy 'storage-deny-public-network-access' {
    Properties @{ DisplayName = 'Storage accounts should disable public network access' }
    Resource 'Microsoft.Storage/storageAccounts' {
        Require 'Public network access is disabled' {
            Field publicNetworkAccess | Must -Be 'Disabled'
        }
    }
    Effect Deny
}

PARAMETERS

-Name

The definition name. It is the definition's identity and output file name, so renaming it creates a new definition. 1 to 64 characters, without < > * % & : \ ? . + / " | or control characters, and not starting or ending with a space (ADR-0010).

Type: String
Required: true
Position: 1
Accept pipeline input: false

-Body

The policy description.

Type: ScriptBlock
Required: true
Position: 2
Accept pipeline input: false