变量

概要

返回配置变量的值。

语法

variables('<name>')

DESCRIPTION

variables() 函数返回特定变量的值。 您必须传递有效变量的名称。 当对资源实例使用此函数时,DSC 会在此函数运行之后和为当前作调用资源之前验证实例属性。 如果引用的变量值对属性无效,DSC 将引发验证错误。

有关在配置文档中定义变量的更多信息,请参阅 DSC 配置文档架构参考

例子

示例 1 - 使用变量作为资源实例属性值

概要示例

# variables.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
variables:
  message: Hello, world!
resources:
  - name: Echo message variable
    type: Microsoft.DSC.Debug/Echo
    properties:
      output: "[variables('message')]"
dsc config get --file variables.example.1.dsc.config.yaml
results:
- metadata:
    Microsoft.DSC:
      duration: PT0.0883345S
  name: Echo message variable
  type: Microsoft.DSC.Debug/Echo
  result:
    actualState:
      output: Hello, world!

参数

姓名

variables() 函数需要一个字符串作为输入,表示要返回的变量的名称。 如果配置文档中未定义具有指定名称的变量,则 DSC 会在验证过程中引发错误。

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

输出

variables() 函数返回指定参数的值。

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