11---
22description : Reference for the 'contains' DSC configuration document function
3- ms.date : 08/08/2025
3+ ms.date : 09/01/2026
44ms.topic : reference
55title : contains
66---
@@ -23,11 +23,14 @@ contains(<collection>, <value>)
2323The ` contains() ` function checks whether a collection (array, object, or
2424string) contains a specific value, returning ` true ` if it does and ` false `
2525otherwise. For arrays, it checks if the value exists as an element. For
26- objects, it checks if the value exists as a property key or value. For
27- strings, it checks if the value exists as a substring.
26+ objects, it checks if the value exists as a property key. The function
27+ doesn't check object property values. For strings, it checks if the value
28+ exists as a substring.
2829
2930The function accepts string and number values for the search parameter when
30- used with arrays, objects, or strings.
31+ used with arrays, objects, or strings. When the search value is a number and
32+ the collection is an object or a string, DSC compares the number by its
33+ string representation.
3134
3235## Examples
3336
@@ -76,10 +79,12 @@ messages: []
7679hadErrors : false
7780` ` `
7881
79- ### Example 2 - Check object for keys and values
82+ ### Example 2 - Check object for keys
8083
81- The following example shows how to check if an object contains specific keys
82- or values.
84+ The following example shows how to check if an object contains specific keys.
85+ For objects, ` contains()` only checks keys, not property values. To check the
86+ contents of a property value, access the property and check it as a string,
87+ like the `cityHasSeattle` output in this example.
8388
8489` ` ` yaml
8590# contains.example.2.dsc.config.yaml
@@ -96,10 +101,10 @@ resources:
96101 type: Microsoft.DSC.Debug/Echo
97102 properties:
98103 output:
99- hasNameKey : " [contains(parameters('myObject'), 'name')]"
100- hasEmailKey : " [contains(parameters('myObject'), 'email')]"
101- hasSeattleValue : " [contains(parameters('myObject').city , 'Seattle ')]"
102- hasAge30Value : " [contains(parameters('myObject').age, 30 )]"
104+ hasNameKey: "[contains(parameters('myObject'), 'name')]"
105+ hasEmailKey: "[contains(parameters('myObject'), 'email')]"
106+ hasAgeKey: "[contains(parameters('myObject'), 'age ')]"
107+ cityHasSeattle: "[contains(parameters('myObject').city, 'Seattle' )]"
103108` ` `
104109
105110` ` ` bash
@@ -115,8 +120,8 @@ results:
115120 output:
116121 hasNameKey: true
117122 hasEmailKey: false
118- hasSeattleValue : true
119- hasAge30Value : true
123+ hasAgeKey : true
124+ cityHasSeattle : true
120125messages: []
121126hadErrors: false
122127` ` `
0 commit comments