Skip to content

BYL1xxx: Front end

Reported while a .bylaw.ps1 file runs, when a keyword is used in the wrong place or with the wrong arguments. They point at the line of the keyword.

Code Severity Meaning
BYL1001 Error Keyword used outside a Policy block
BYL1002 Error Keyword in the wrong block
BYL1003 Error Nested Policy or Initiative
BYL1004 Error Keyword used more than once
BYL1005 Error Policy has no Resource block
BYL1006 Error Policy has no effect
BYL1007 Error Field or count not piped to anything
BYL1008 Error Must has nothing to test
BYL1009 Error Must needs exactly one operator
BYL1010 Error -IfPresent or -Strict where it doesn't apply
BYL1011 Error Unknown Properties key
BYL1012 Error Properties value of the wrong type
BYL1013 Error Empty block
BYL1014 Error Policy or Initiative stopped by an error
BYL1015 Error Invalid Parameter declaration
BYL1016 Error Each needs an array path ending in [*]
BYL1017 Error Require needs a description
BYL1019 Error Effect needs an effect name or a parameter
BYL1020 Error Param or Arm inside an array or hashtable value
BYL1021 Error Invalid resource type
BYL1022 Error AllOf outside AnyOf
BYL1023 Error Invalid tag name
BYL1024 Error Expression tested where only a field can be
BYL1025 Error Field used as a value
BYL1026 Error More than one effect
BYL1027 Error Operation with the wrong value
BYL1028 Error -Condition needs an Arm expression
BYL1029 Error Invalid -ConflictEffect
BYL1030 Error -Effect needs a parameter
BYL1031 Error Operation needs a field
BYL1032 Error Role needed for remediation
BYL1033 Error DenyAction supports only Delete
BYL1034 Error Invalid -CascadeBehavior
BYL1035 Error Invalid -DefaultState
BYL1036 Error Operation not allowed in Append
BYL1037 Error -Condition in Append
BYL1038 Error IfNotExists effect needs -Type
BYL1039 Error Invalid name or location value
BYL1040 Error Invalid scope
BYL1041 Error Invalid -EvaluationDelay
BYL1043 Error DeployIfNotExists needs a Deployment
BYL1044 Error Deployment needs one template
BYL1045 Error Invalid deployment template
BYL1046 Error Subscription deployment needs -Location
BYL1047 Error Invalid Count
BYL1048 Error Invalid Count -Name
BYL1049 Error Nested value count needs -Name
BYL1050 Error Invalid Current
BYL1051 Error Operator a count doesn't take
BYL1052 Error Count used as a value
BYL1053 Error Invalid definition version
BYL1054 Error Initiative has no members
BYL1055 Error PolicyDefinition needs a name or -Id
BYL1056 Error Missing or empty -ReferenceId
BYL1057 Error Missing definition group name
BYL1059 Error Tag named with Current
BYL1060 Error Invalid raw condition
BYL1061 Error Condition needs -Violation or -Compliant
BYL1062 Error KeyVaultSecret takes a string, Param or Arm
BYL1063 Error KeyVaultSecret outside Deployment -Parameters

BYL1001

Keyword used outside a Policy block (error)

Bylaw's keywords only exist while a Policy or Initiative block runs, so they don't clash with other commands. A keyword such as Field, Param or Arm was used outside one, at the top of the file or in a function called from outside the block.

To fix it: Move the statement inside a Policy or Initiative block. To share statements between policies, put them in a scriptblock or function and call it from inside each block.

For example:

Policy 'storage-tls' {
    Resource 'Microsoft.Storage/storageAccounts' {
        Require 'TLS 1.2' {
            Field minimumTlsVersion | Must -Be 'TLS1_2'
        }
    }
    Effect Deny
}

See ADR-0005.

BYL1002

Keyword in the wrong block (error)

Each keyword can only be used inside certain blocks: for example Require goes inside Resource, and Must inside When, Require, Each or a group. The message names the blocks it is allowed in. It is also reported for Element in a value count, where the member is Current, and for Tag inside Each, where field names refer to the array element.

To fix it: Move the keyword into one of the blocks the message names. The keyword's wiki page lists them under Used in.

See ADR-0005.

BYL1003

Nested Policy or Initiative (error)

A Policy or Initiative was declared inside another one. Each is a definition of its own, so it must be at the top level of the file.

To fix it: Move the inner Policy or Initiative out, after the closing brace of the outer one. A file can hold several of them.

BYL1004

Keyword used more than once (error)

Properties and Resource can appear only once in a Policy, and Deployment only once in a DeployIfNotExists. The message gives the line of the first one.

To fix it: Merge the two into one: all the properties in one Properties hashtable, or all the requirements in one Resource. A policy has one resource type; for several, use one policy each, or Resource * with a type condition in When.

BYL1005

Policy has no Resource block (error)

A policy needs a Resource block: it sets the resource type the policy applies to, and holds the When and Require blocks.

To fix it: Add Resource '' { ... } for one resource type, or Resource * { ... } for every type.

For example:

Resource 'Microsoft.Storage/storageAccounts' {
    Require 'TLS 1.2' {
        Field minimumTlsVersion | Must -Be 'TLS1_2'
    }
}

BYL1006

Policy has no effect (error)

Every policy has exactly one effect, which says what Azure does with a non-compliant resource. None of the effect keywords was used.

To fix it: Add Effect Audit, Effect Deny or Effect (Param Effect), or one of the effect blocks: Modify, Append, DenyAction, Manual, AuditIfNotExists or DeployIfNotExists.

See ADR-0017.

BYL1007

Field or count not piped to anything (error)

Field, Tag, Element and Count only describe what to test. On their own they do nothing, so a line with one that isn't piped to Must (or, in Modify, to an operation) is almost certainly a mistake.

To fix it: Pipe it to Must with an operator, or inside Modify and Append to AddOrReplace, Add or Remove.

For example:

Field publicNetworkAccess | Must -Be 'Disabled'
Count securityRules[*] | Must -BeLessOrEqual 10

BYL1008

Must has nothing to test (error)

Must tests what is piped to it, and nothing was: it was called on its own, or after something that isn't a field, tag, element, count or value.

To fix it: Pipe a Field, Tag, Element or Count, or a value such as ResourceGroupTag, Param or Arm, to Must.

For example:

Field publicNetworkAccess | Must -Be 'Disabled'

BYL1009

Must needs exactly one operator (error)

Each Must statement tests one thing, so it takes one operator, such as -Be or -BeIn. It had none or several. -Not, -IfPresent and -Strict change an operator and don't count as one.

To fix it: Use one operator per Must. To test several things, write several Must statements: in a Require, they must all hold.

For example:

Field minimumTlsVersion | Must -BeIn 'TLS1_2', 'TLS1_3'
Field allowBlobPublicAccess | Must -Be $false

BYL1010

-IfPresent or -Strict where it doesn't apply (error)

-IfPresent makes a missing field compliant, and -Strict makes a missing field on an array element a violation. They only mean something where Bylaw adds missing-field checks: -IfPresent in Require, and -Strict inside Each. They can't be used together, and When and Count -Where are emitted as written, so neither applies there.

To fix it: Remove the switch, or move the statement to where it applies. In When, write the missing-field case out with -Exist if you need it.

See ADR-0004.

BYL1011

Unknown Properties key (error)

Properties only takes the keys Bylaw knows how to emit, so a misspelled key fails instead of being dropped. The message suggests the closest key. An initiative has no Mode: each member policy has its own.

To fix it: Use one of the keys the message lists: DisplayName, Description, Category, Version, Mode, Preview, Deprecated or Metadata. Put other metadata in Metadata.

BYL1012

Properties value of the wrong type (error)

DisplayName, Description, Category, Version and Mode are strings, Preview and Deprecated are $true or $false, and Metadata is a hashtable.

To fix it: Give the key a value of the type the message names, e.g. Version = '1.0.0' in quotes, or Preview = $true.

BYL1013

Empty block (error)

A block that should hold statements is missing or has none: When, Require, Each, AnyOf or AllOf without a Must, Modify or Append without an operation, or Count -Where without a condition. An empty block would emit an empty condition, which Azure rejects or which matches everything.

To fix it: Add the statements the block needs, or remove it. For Count, leave out -Where to count every element.

BYL1014

Policy or Initiative stopped by an error (error)

PowerShell raised an error while the block ran, for example a mistyped command, a failing expression or a throw in your own code. Bylaw reports it with the block's name and stops compiling that definition.

To fix it: Read the error in the message: it is PowerShell's own. Fix the line it points to, as you would in any script.

BYL1015

Invalid Parameter declaration (error)

A Parameter was declared in a way Bylaw can't use: no name, a name with characters other than letters, digits and underscores, a name declared twice, an unknown type or option, a type that can't be inferred, or the hashtable form mixed with named options.

To fix it: Give the parameter a name, and its options either as named parameters or as one hashtable. Add -Type when there's no default or allowed values to infer it from.

For example:

Parameter Effect -AllowedValues Audit, Deny, Disabled -Default Audit
Parameter AllowedLocations @{ Type = 'Array'; Metadata = @{ strongType = 'location' } }

See ADR-0021.

BYL1016

*Each needs an array path ending in [] (error)

Each goes through the elements of an array, so its path must name an array with [*] at the end, as Azure's aliases do.

To fix it: Add [] to the path, e.g. networkAcls.ipRules[].

For example:

Each networkAcls.ipRules[*] {
    Field value | Must -Not -Be '0.0.0.0/0'
}

BYL1017

Require needs a description (error)

Every Require is named with what it requires, so the source reads as a list of requirements and error messages can refer to them.

To fix it: Give the Require a description before its block.

For example:

Require 'Public network access is disabled' {
    Field publicNetworkAccess | Must -Be 'Disabled'
}

BYL1019

Effect needs an effect name or a parameter (error)

Effect takes the name of an effect, or a Param that holds one. Something else was given, such as a number or an expression.

To fix it: Use Effect Deny (or Audit or Disabled), or Effect (Param Effect).

BYL1020

Param or Arm inside an array or hashtable value (error)

Azure Policy can only use a parameter or an expression as a whole value. An array that mixes literals with Param or Arm, or a hashtable with Param or Arm inside it, has no JSON form.

To fix it: Use one parameter for the whole value: an Array parameter for a list, or an Object parameter for a hashtable.

For example:

Parameter AllowedValues -Type Array -Default @('a', 'b')
Field kind | Must -BeIn (Param AllowedValues)

BYL1021

Invalid resource type (error)

Resource takes a resource type in the form Namespace/type, such as Microsoft.Storage/storageAccounts, with child types after further slashes.

To fix it: Correct the type, or use Resource * for a policy that applies to every type.

BYL1022

AllOf outside AnyOf (error)

Statements in When, Require, Each and Count -Where already all have to hold, so AllOf is only needed inside AnyOf, to make one alternative out of several statements.

To fix it: Remove the AllOf and keep its statements.

See ADR-0026.

BYL1023

Invalid tag name (error)

Tag and ResourceGroupTag take a tag name or a Param that holds one. A literal name can't contain ', [ or ], because it is written inside tags['...']. In a field count, Current is an array element, not a tag name.

To fix it: Use the tag's name, or Tag (Param TagName). For a tag name with those characters, write the expression with Arm.

See ADR-0020.

BYL1024

Expression tested where only a field can be (error)

A value condition tests an expression such as ResourceGroupTag or Arm, not a field. An expression is never missing, so -Exist, -IfPresent and -Strict don't apply to it, and testing one inside Each isn't supported yet.

To fix it: Use -Not -Be '' to require a value, and remove -IfPresent or -Strict. Inside Each, test the expression in a separate Require or in When.

See ADR-0025.

BYL1025

Field used as a value (error)

A Field describes what to test, so it goes on the left of Must, not as the value to compare with.

To fix it: Pipe the field to Must. To compare two fields, write the other one with Arm.

For example:

Field location | Must -Be (Arm '[resourceGroup().location]')

BYL1026

More than one effect (error)

A policy has exactly one effect. Two effect keywords were used, for example Effect and Modify. The message gives the line of the first.

To fix it: Keep one. To let an assignment choose, use an effect parameter: Effect (Param Effect), or -Effect (Param Effect) on Modify, DenyAction and the other effect blocks.

See ADR-0017.

BYL1027

Operation with the wrong value (error)

AddOrReplace and Add need the value to set. Remove takes none: it removes the field.

To fix it: Give AddOrReplace and Add a value, and remove the value from Remove.

For example:

Tag Environment | AddOrReplace 'Production'
Tag TempResource | Remove

See ADR-0024.

BYL1028

-Condition needs an Arm expression (error)

A Modify operation's -Condition is an ARM expression that is true or false, evaluated by Azure for each resource.

To fix it: Pass an Arm expression.

For example:

Tag Environment | AddOrReplace 'Production' -Condition (Arm "[equals(parameters('mode'), 'strict')]")

See ADR-0024.

BYL1029

Invalid -ConflictEffect (error)

Modify's -ConflictEffect says what happens when two Modify policies change the same field. Azure accepts Audit, Deny and Disabled.

To fix it: Use -ConflictEffect Audit, Deny or Disabled.

See ADR-0024.

BYL1030

-Effect needs a parameter (error)

On Modify, Append, DenyAction, Manual and the IfNotExists effects, -Effect is only for letting an assignment choose the effect, so it takes a Param or an Arm expression, not a literal. Without it, the effect is the keyword's own.

To fix it: Use -Effect (Param Effect), with a parameter whose allowed values include the keyword's effect and Disabled, or leave -Effect out.

BYL1031

Operation needs a field (error)

AddOrReplace, Add and Remove change the field piped to them, and nothing was.

To fix it: Pipe a Field or Tag to the operation.

For example:

Tag CostCenter | Add (ResourceGroupTag CostCenter)

BYL1032

Role needed for remediation (error)

Modify and DeployIfNotExists change resources through the assignment's managed identity, so Azure needs the roles that identity must have. Bylaw writes them as roleDefinitionIds.

To fix it: Add -Role with a built-in role name or a role definition ID, e.g. -Role 'Tag Contributor'.

See ADR-0022.

BYL1033

DenyAction supports only Delete (error)

Azure's denyAction effect can only block delete requests today.

To fix it: Use DenyAction Delete.

See ADR-0017.

BYL1034

Invalid -CascadeBehavior (error)

DenyAction's -CascadeBehavior says whether deleting a parent, such as a resource group, is blocked when it would delete a protected resource. Azure accepts Deny and Allow.

To fix it: Use -CascadeBehavior Deny or Allow.

See ADR-0017.

BYL1035

Invalid -DefaultState (error)

Manual's -DefaultState is the compliance state before anyone attests. Azure accepts Unknown, Compliant and NonCompliant.

To fix it: Use -DefaultState Unknown, Compliant or NonCompliant.

See ADR-0017.

BYL1036

Operation not allowed in Append (error)

Append can only add values to a create or update request. AddOrReplace and Remove need the modify effect.

To fix it: Use Add in Append, or use Modify to replace or remove a value.

See ADR-0029.

BYL1037

-Condition in Append (error)

Azure's append details have no conditions, so Add in Append can't take -Condition.

To fix it: Put the condition in When or Require instead.

See ADR-0029.

BYL1038

IfNotExists effect needs -Type (error)

AuditIfNotExists and DeployIfNotExists check for a related resource, such as a VM extension or diagnostic setting, and need its resource type.

To fix it: Add -Type with the related resource's type.

For example:

AuditIfNotExists -Type 'Microsoft.Compute/virtualMachines/extensions' {
    Require 'The antimalware extension is installed' {
        Field publisher | Must -Be 'Microsoft.Azure.Security'
        Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -Be 'IaaSAntimalware'
    }
}

See ADR-0030.

BYL1039

Invalid name or location value (error)

-Name and -ResourceGroupName on the IfNotExists effects, and -Location on Deployment, take a literal, a Param or an Arm expression.

To fix it: Pass one of those, e.g. -Name (Arm "[field('name')]") or -Location (Param Location).

See ADR-0030.

BYL1040

Invalid scope (error)

Deployment -Scope and the IfNotExists effects' -ExistenceScope take ResourceGroup or Subscription.

To fix it: Use ResourceGroup or Subscription.

See ADR-0030.

BYL1041

Invalid -EvaluationDelay (error)

-EvaluationDelay says when Azure checks for the related resource after a change. Azure accepts AfterProvisioning, AfterProvisioningSuccess, AfterProvisioningFailure, or an ISO 8601 duration from 0 to 360 minutes. A parameter or an Arm expression is emitted as written.

To fix it: Use one of the three names, a duration such as PT30M, or a parameter such as (Param EvaluationDelay).

See ADR-0030.

BYL1043

DeployIfNotExists needs a Deployment (error)

DeployIfNotExists deploys a template when the related resource is missing, so its block needs a Deployment with the template.

To fix it: Add a Deployment to the block.

For example:

DeployIfNotExists -Type 'Microsoft.Insights/diagnosticSettings' -Role 'Contributor' {
    Require 'Logs go to the workspace' {
        Field workspaceId | Must -Be (Param WorkspaceId)
    }
    Deployment -TemplateFile ./templates/diagnostic-settings.json -Parameters @{
        workspaceId = Param WorkspaceId
    }
}

See ADR-0031.

BYL1044

Deployment needs one template (error)

Deployment takes the template either from a JSON file with -TemplateFile or as a hashtable with -Template. It had neither or both.

To fix it: Use exactly one of -TemplateFile and -Template.

See ADR-0031.

BYL1045

Invalid deployment template (error)

The template file couldn't be found or read as JSON, it isn't an ARM template (an object with a resources array), or a -Template hashtable contains Param or Arm. The template is evaluated by the deployment, not by the policy.

To fix it: Check the path, which is relative to the .bylaw.ps1 file, and the JSON. Pass policy values with -Parameters, and use them in the template as [parameters('name')].

See ADR-0031.

BYL1046

Subscription deployment needs -Location (error)

Azure requires a location for a deployment at subscription scope, to store its metadata.

To fix it: Add -Location to the Deployment, e.g. -Location (Param Location).

See ADR-0031.

BYL1047

Invalid Count (error)

Count is a field count with an array path ending in [], or a value count with -Value and a list: an array, a Param or an Arm expression. It had both, neither, a path without [], or a -Value that isn't a list.

To fix it: Use Count path[*] or Count -Value .

For example:

Count networkAcls.ipRules[*] | Must -BeGreaterThan 0
Count -Value (Param NamePatterns) -Name pattern -Where { Field name | Must -BeLike (Current pattern) } | Must -BeGreaterThan 0

See ADR-0032.

BYL1048

Invalid Count -Name (error)

-Name names the member of a value count, so Current can refer to it. A field count has no -Name: Current is the element. Azure only allows letters and digits.

To fix it: Remove -Name from a field count, or use a name of letters and digits, e.g. -Name tagName.

See ADR-0032.

BYL1049

Nested value count needs -Name (error)

Azure requires a name for a value count inside another count, including one inside Each, so the two members can be told apart.

To fix it: Add -Name to the inner count, and refer to it with Current .

See ADR-0032.

BYL1050

Invalid Current (error)

Current is the element or member being counted, so it only exists inside Count -Where. Current must match the -Name of a value count around it, and Current without a name is ambiguous in a value count inside another count.

To fix it: Use Current inside -Where, with the name of the count you mean.

See ADR-0032.

BYL1051

Operator a count doesn't take (error)

A count is a number, so it is tested with -Be, -BeIn, -BeGreaterThan, -BeGreaterOrEqual, -BeLessThan or -BeLessOrEqual. A count is never missing, so -IfPresent and -Strict don't apply either.

To fix it: Use one of those operators, without -IfPresent or -Strict.

See ADR-0032.

BYL1052

Count used as a value (error)

A Count is something to test, so it goes on the left of Must, not as a value.

To fix it: Pipe the count to Must.

For example:

Count securityRules[*] | Must -BeLessOrEqual 10

See ADR-0032.

BYL1053

Invalid definition version (error)

PolicyDefinition -Version is the definitionVersion Azure uses to pick a version of the member: a major version, then a minor version or *, then a patch or *, optionally with -preview.

To fix it: Use a version such as '1..' or '2.1.*'.

See ADR-0033.

BYL1054

Initiative has no members (error)

An initiative groups policies, so it needs at least one PolicyDefinition.

To fix it: Add the policies it includes: by name for a policy in this build, or by -Id for a built-in one.

For example:

PolicyDefinition 'general-require-tag' -Parameters @{ tagName = 'CostCenter' }
PolicyDefinition -Id 96670d01-0a4d-4649-9c89-2d3abc0a5025 -ReferenceId 'require-environment' -Parameters @{ tagName = 'Environment' }

See ADR-0033.

BYL1055

PolicyDefinition needs a name or -Id (error)

A member is either a policy in this build, by name, or another definition, by -Id. It had both or neither.

To fix it: Use PolicyDefinition 'policy-name' or PolicyDefinition -Id -ReferenceId .

See ADR-0033.

BYL1056

Missing or empty -ReferenceId (error)

The reference ID is the short name the initiative uses for a member. It defaults to the policy's name for a member from the build, but a member by -Id needs one, and an empty one is never valid.

To fix it: Add -ReferenceId with a short name, e.g. -ReferenceId InheritCostCenter.

See ADR-0033.

BYL1057

Missing definition group name (error)

DefinitionGroup needs a name, and PolicyDefinition -Group needs the names of the groups the member belongs to.

To fix it: Give the group a name, and refer to it by that name in -Group.

For example:

DefinitionGroup 'AC-2' -DisplayName 'Account Management'
PolicyDefinition 'general-require-tag' -Group 'AC-2'

See ADR-0033.

BYL1059

Tag named with Current (error)

Tag (Current name) would emit a field named with current(), and Azure rejects that: "'field' and 'current' functions are not supported in the 'field' accessor".

To fix it: To require that the tags exist, test the tags object for each name instead, with Field tags | Must -ContainKey (Current tagName). To test their values, check each tag with its own Tag, or with Tag (Param TagName) in a policy that an initiative includes once per tag.

For example:

Count -Value (Param MandatoryTags) -Name tagName -Where {
    Field tags | Must -ContainKey (Current tagName)
} | Must -Be (Param MandatoryTags -Length)

Tag CostCenter | Must -Be 'Finance'

See ADR-0032.

BYL1060

Invalid raw condition (error)

Condition takes one Azure Policy condition, as a hashtable or JSON text: exactly one of allOf, anyOf, not, field, value or count, and for a field, value or count condition exactly one operator. A count needs field (an array alias ending in [*]) or value (a list), and name only for a value count. The message says where in the condition the problem is, e.g. condition.anyOf[1].

To fix it: Correct the condition at the place the message names. It has the same shape as in policy JSON, with Param and Arm allowed for values.

For example:

Condition -Violation @{ field = 'location'; notIn = (Param AllowedLocations) }

See ADR-0040.

BYL1061

Condition needs -Violation or -Compliant (error)

Statements in Require and Each describe the compliant state and are inverted, which Bylaw can't do correctly for a raw condition. So a Condition there says which form it is: -Violation finds a non-compliant resource and is emitted as written; -Compliant is the compliant state and is emitted as not(...). In When and Count -Where, conditions are emitted as written, so the switches mean nothing there, and one switch at a time is allowed.

To fix it: In Require and Each, add -Violation or -Compliant. In When and Count -Where, remove the switch.

For example:

Require 'No test resources' {
    Condition -Violation @{ field = 'name'; like = 'test-*' }
}

See ADR-0040.

BYL1062

KeyVaultSecret takes a string, Param or Arm (error)

Each part of a Key Vault reference, -VaultId, -SecretName and -SecretVersion, is a string in the deployment: a literal, or an expression such as a policy parameter.

To fix it: Pass a non-empty string, (Param Name) or (Arm "[...]").

For example:

domainPassword = (KeyVaultSecret -VaultId (Param KeyVaultResourceId) -SecretName 'domain-password')

See ADR-0043.

BYL1063

KeyVaultSecret outside Deployment -Parameters (error)

Only a deployment can read a secret from Key Vault, so KeyVaultSecret is a value only for a template parameter. It can't be compared with, set by Modify or Append, or passed to an initiative member.

To fix it: Pass it in Deployment -Parameters, or use Param for a value assigned with the policy.

For example:

Deployment -TemplateFile ./templates/domain-join.json -Parameters @{
    domainPassword = (KeyVaultSecret -VaultId (Param KeyVaultResourceId) -SecretName 'domain-password')
}

See ADR-0043.