en-AU/about_PSRule_Variables.help.txt

TOPIC
    about_psrule_variables
 
SHORT DESCRIPTION
    Describes the automatic variables that can be used within PSRule rule
    definitions.
 
LONG DESCRIPTION
    PSRule lets you define rules using PowerShell blocks. A rule is defined
    within script files by using the `rule` keyword.
    Within a rule definition, PSRule exposes a number of automatic variables
    that can be read to assist with rule execution. Overwriting these variables
    or variable properties is not supported.
    These variables are only available while `Invoke-PSRule` is executing.
    The following variables are available for use:
    -
    $Configuration
    -
    $Rule
    -
    $TargetObject
 
    CONFIGURATION
    A configuration object with properties names for each configuration value
    set in the baseline.
    When accessing configuration:
    - Configuration values are read only.
    - Property names are case sensitive.
    Syntax:
 
    $Configuration
 
    Examples:
 
    # This rule uses a threshold stored as $Configuration.appServiceMinInstanceCount
    Rule 'appServicePlan.MinInstanceCount' -If { $TargetObject.ResourceType -eq 'Microsoft.Web/serverfarms' } {
        $TargetObject.Sku.capacity -ge $Configuration.appServiceMinInstanceCount
    } -Configure @{ appServiceMinInstanceCount = 2 }
 
    RULE
    An object representing the current object model of the rule during execution.
    The following section properties are available for public read access:
    - `RuleName` - The name of the rule.
    - `RuleId` - A unique identifier for the rule.
    - `TargetObject` - The object currently being processed on the pipeline.
    - `TargetName` - The name of the object currently being processed on the
    pipeline. This property will automatically default to `TargetName` or `Name`
    properties of the object if they exist.
    - `TargetType` - The type of the object currently being processed on the
    pipeline. This property will automatically bind to `PSObject.TypeNames[0]`
    by default.
    Syntax:
 
    $Rule
 
    Examples:
 
    # This rule determined if the target object matches the naming convention
    Rule 'resource.NamingConvention' {
        $Rule.TargetName.ToLower() -ceq $Rule.TargetName
    }
 
    TARGETOBJECT
    The value of the pipeline object currently being processed. `$TargetObject`
    is set by using the `-InputObject` parameter of `Invoke-PSRule`.
    When more than one input object is set, each object will be processed sequentially.
    Syntax:
 
    $TargetObject
 
    Examples:
 
    # Check that sku capacity is set to at least 2
    Rule 'HasMinInstances' {
        $TargetObject.Sku.capacity -ge 2
    }
 
NOTE
    An online version of this document is available at
    https://github.com/BernieWhite/PSRule/blob/master/docs/concepts/PSRule/en-US/about_PSRule_Variables.md.
 
SEE ALSO
    -
    Invoke-PSRule
 
KEYWORDS
    - Configuration
- Rule
- TargetObject