概要
返回配置變數的值。
語法
variables('<name>')
說明
該 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]