| description | Reference for the 'envvar' DSC configuration document function |
|---|---|
| ms.date | 02/28/2025 |
| ms.topic | reference |
| title | envvar |
Returns the value of an environment variable.
envvar(<variableName>)The envvar() function returns the value of an environment variable as a string. If the
environment variable doesn't exist, DSC raises an error.
When you use the --path option to specify a configuration document for any of the dsc config *
commands, DSC automatically creates the DSC_CONFIG_ROOT environment variable and sets the value to
the parent folder of the specified configuration document. For more information, see
dsc config command reference.
This configuration echoes that folder with the Microsoft.DSC.Debug/Echo resource.
# ./examples/envvar.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo 'DSC_CONFIG_ROOT' in envvar
type: Microsoft.DSC.Debug/Echo
properties:
output: "[envvar('DSC_CONFIG_ROOT')]"dsc config get --path ~/dsc/examples/envvar.example.1.dsc.config.yamlresults:
- name: Echo DSC_CONFIG_ROOT
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: ~/dsc/examples
messages: []
hadErrors: falseThe envvar() function expects a single string representing the name of the environment variable
to use. If the value isn't a string, DSC raises an error when validating the configuration
document. If the environment variable named by the input doesn't exist, DSC raises an error.
Type: string
Required: true
MinimumCount: 1
MaximumCount: 1The envvar() function returns the value of the environment variable specified with the
variableName parameter.
Type: string