概要
返回配置參數的值。
語法
parameters('<name>')
說明
該 parameters() 函數返回特定參數的值。 您必須傳遞有效參數的名稱。 當對資源實例使用此函數時,DSC 會在此函數運行之後和為當前作調用資源之前驗證實例屬性。 如果引用的參數值對屬性無效,DSC 將引發驗證錯誤。
有關在配置文件中定義參數的更多資訊,請參閱 DSC 設定文件的參數架構。
範例
範例 1 - 使用參數作為資源實例屬性值
該配置使用 function parameters() 來回顯 parameter 的值 message 。
# parameters.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
message:
type: string
defaultValue: Hello, world!
resources:
- name: Echo message parameter
type: Microsoft.DSC.Debug/Echo
properties:
output: "[parameters('message')]"
首先,獲取配置的當前狀態,而不使用 --parameters 或 --parameters_file options 覆蓋參數。 輸出顯示參數的 message 預設值。
config_file=parameters.example.1.dsc.config.yaml
cat $config_file | dsc config get
results:
- name: Echo message parameter
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: Hello, world!
messages: []
hadErrors: false
接下來,使用 --parameters option 覆蓋參數message。
params='{"parameters": {"message": "Hi, override."}}'
cat $config_file | dsc config --parameters $params get
results:
- name: Echo message parameter
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: Hi, override.
messages: []
hadErrors: false
參數
名稱
該 parameters() 函數需要一個字串作為輸入,表示要返回的參數的名稱。 如果配置文件中未定義具有指定名稱的參數,DSC 會在驗證過程中引發錯誤。
Type: string
Required: true
MinimumCount: 1
MaximumCount: 1
輸出
該 parameters() 函數返回指定參數的值。
Type: [string, int, bool, object, array]