| description | Reference for the 'createArray' DSC configuration document function |
|---|---|
| ms.date | 02/28/2025 |
| ms.topic | reference |
| title | createArray |
Returns an array of values from input.
createArray(<inputValue>)The createArray() function returns an array of values from the input values. You can use this
function to create arrays of any type. The input values must be of the same type - numbers,
strings, objects, or arrays. When the input values are objects or arrays, they do not need be
objects with the same properties or arrays of the same type. When the input values are arrays, the
function returns an array of arrays.
The following example shows how to create a simple array with integers.
# createArray.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo array of integers
type: Microsoft.DSC.Debug/Echo
properties:
output: "[createArray(1, 3, 5)]"dsc config get --file createArray.example.1.dsc.config.yaml config getresults:
- name: Echo array of integers
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
- 1
- 3
- 5
messages: []
hadErrors: falseThis configuration returns an array where the items in the array are also arrays. The first sub-array contains only integers. The second sub-array contains only strings.
# createArray.example.2.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Create array of arrays
type: Microsoft.DSC.Debug/Echo
properties:
output: "[createArray(createArray(1,3,5), createArray('a', 'b', 'c'))]"dsc config get --file createArray.example.2.dsc.config.yamlresults:
- name: Create array of arrays
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
- - 1
- 3
- 5
- - a
- b
- c
messages: []
hadErrors: falseThis configuration uses the concat() function to concatenate two newly created arrays of strings. It uses YAML's folded multiline string syntax to make the function more readable.
# createArray.example.3.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo flattened array
type: Microsoft.DSC.Debug/Echo
properties:
output: >-
[concat(
createArray('a', 'b', 'c'),
createArray('d', 'e', 'f')
)]dsc config get --file createArray.example.3.dsc.config.yamlresults:
- name: Echo flattened array
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
- a
- b
- c
- d
- e
- f
messages: []
hadErrors: falseThe createArray() function expects zero or more input values of the same type. Separate each
value with a comma. If the type of any input value is different from the first value, DSC returns
an error for the function.
Type: [integer, string, number, object, array]
Required: false
MinimumCount: 0
MaximumCount: 18446744073709551615The createArray() function returns an array of values. When the input values are arrays, the
returned value is an array of arrays, not a flattened array of the input values. You can return a
flattened array of string arrays with the concat() function, as in
example 3.
Type: array