Skip to content

Latest commit

 

History

History
89 lines (66 loc) · 1.97 KB

variables.md

File metadata and controls

89 lines (66 loc) · 1.97 KB
description ms.date ms.topic title
Reference for the 'variables' DSC configuration document function
08/22/2024
reference
variables

variables

Synopsis

Returns the value of a configuration variable.

Syntax

variables('<name>')

Description

The variables() function returns the value of a specific variable. You must pass the name of a valid variable. When using this function for a resource instance, DSC validates the instance properties after this function runs and before calling the resource for the current operation. If the referenced variable value is invalid for the property, DSC raises a validation error.

For more information about defining variables in a configuration document, see DSC Configuration document schema reference.

Examples

Example 1 - Use a variable as a resource instance property value

example synopsis

# variables.example.1.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
variables:
  message: Hello, world!
resources:
  - name: Echo message variable
    type: Test/Echo
    properties:
      output: "[variables('message')]"
dsc config get --document variables.example.1.dsc.config.yaml
results:
- metadata:
    Microsoft.DSC:
      duration: PT0.0883345S
  name: Echo message variable
  type: Test/Echo
  result:
    actualState:
      output: Hello, world!

Parameters

name

The variables() function expects a single string as input, representing the name of the variable to return. If no variable with the specified name is defined in the configuration document, DSC raises an error during validation.

Type:         string
Required:     true
MinimumCount: 1
MaximumCount: 1

Output

The variables() function returns the value of the specified parameter.

Type: [string, int, bool, object, array]