Skip to content

Each

SYNOPSIS

Every element of an array must satisfy the block. Compiles to count/where (ADR-0002).

SYNTAX

Each [-Path] <String> [-Body] <ScriptBlock> [-Where <ScriptBlock>] [<CommonParameters>]

DESCRIPTION

Field names inside Each are relative to the element, and Element is the element itself when the array holds plain values. A missing or empty array is compliant, as in Azure. Inside Each, a missing field on an element is compliant unless -Strict is used on Must.

USED IN

Require, Each, AnyOf, AllOf

EXAMPLES

Example 1

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

Example 2

Each accessPolicies[*] {
    Each permissions.keys[*] {
        Element | Must -Not -Be 'purge'
    }
}

Example 3

Each securityRules[*] -Where {
    Field direction | Must -Be 'Inbound'
    Field access | Must -Be 'Allow'
} {
    Field sourceAddressPrefix | Must -Not -BeIn '*', 'Internet'
}

Every inbound rule that allows traffic must not come from the internet. -Where selects the elements, as written, like Count -Where (ADR-0049).

PARAMETERS

-Path

The array, ending in [], e.g. networkAcls.ipRules[]. Inside another Each, it is relative to that element.

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

-Body

The requirement every element must meet.

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

-Where

Selects the elements the requirement applies to, emitted as written, like Count -Where. Without it, every element must meet the requirement.

Type: ScriptBlock
Required: false
Position: named
Accept pipeline input: false