description | ms.date | ms.topic | title |
---|---|---|---|
Reference for the 'variables' DSC configuration document function |
08/22/2024 |
reference |
variables |
Returns the value of a configuration variable.
variables('<name>')
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.
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!
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
The variables()
function returns the value of the specified parameter.
Type: [string, int, bool, object, array]