|
| 1 | +--- |
| 2 | +description: Reference for the 'and' DSC configuration document function |
| 3 | +ms.date: 01/19/2025 |
| 4 | +ms.topic: reference |
| 5 | +title: and |
| 6 | +--- |
| 7 | + |
| 8 | +# and |
| 9 | + |
| 10 | +## Synopsis |
| 11 | + |
| 12 | +Returns true if all arguments are true. |
| 13 | + |
| 14 | +## Syntax |
| 15 | + |
| 16 | +```Syntax |
| 17 | +and(<arg1>, <arg2>, ...) |
| 18 | +``` |
| 19 | + |
| 20 | +## Description |
| 21 | + |
| 22 | +The `and()` function evaluates if all arguments are true. It takes two or more boolean arguments |
| 23 | +and returns `true` only if every argument is `true`. If any argument is `false`, the function |
| 24 | +returns `false`. |
| 25 | + |
| 26 | +This function uses short-circuit evaluation, meaning it returns `false` as soon as it encounters |
| 27 | +the first `false` argument without evaluating the remaining arguments. |
| 28 | + |
| 29 | +## Examples |
| 30 | + |
| 31 | +### Example 1 - Basic and operation |
| 32 | + |
| 33 | +This configuration demonstrates basic usage of the `and()` function. |
| 34 | + |
| 35 | +```yaml |
| 36 | +# and.example.1.dsc.config.yaml |
| 37 | +$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 38 | +resources: |
| 39 | + - name: Echo and result |
| 40 | + type: Microsoft.DSC.Debug/Echo |
| 41 | + properties: |
| 42 | + output: "[and(true, true)]" |
| 43 | +``` |
| 44 | +
|
| 45 | +```bash |
| 46 | +dsc config get --file and.example.1.dsc.config.yaml |
| 47 | +``` |
| 48 | + |
| 49 | +```yaml |
| 50 | +results: |
| 51 | +- metadata: |
| 52 | + Microsoft.DSC: |
| 53 | + duration: PT0.1291763S |
| 54 | + name: Echo and result |
| 55 | + type: Microsoft.DSC.Debug/Echo |
| 56 | + result: |
| 57 | + actualState: |
| 58 | + output: true |
| 59 | +messages: [] |
| 60 | +hadErrors: false |
| 61 | +``` |
| 62 | +
|
| 63 | +### Example 2 - And operation with false value |
| 64 | +
|
| 65 | +This example shows the `and()` function returning false when one argument is false. |
| 66 | + |
| 67 | +```yaml |
| 68 | +# and.example.2.dsc.config.yaml |
| 69 | +$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 70 | +resources: |
| 71 | + - name: Echo and result with false |
| 72 | + type: Microsoft.DSC.Debug/Echo |
| 73 | + properties: |
| 74 | + output: "[and(true, false, true)]" |
| 75 | +``` |
| 76 | + |
| 77 | +```bash |
| 78 | +dsc config get --file and.example.2.dsc.config.yaml |
| 79 | +``` |
| 80 | + |
| 81 | +```yaml |
| 82 | +results: |
| 83 | +- metadata: |
| 84 | + Microsoft.DSC: |
| 85 | + duration: PT0.0329292S |
| 86 | + name: Echo and result with false |
| 87 | + type: Microsoft.DSC.Debug/Echo |
| 88 | + result: |
| 89 | + actualState: |
| 90 | + output: false |
| 91 | +messages: [] |
| 92 | +hadErrors: false |
| 93 | +``` |
| 94 | + |
| 95 | +### Example 3 - And operation with multiple conditions |
| 96 | + |
| 97 | +This configuration uses the `and()` function with multiple boolean expressions. |
| 98 | + |
| 99 | +```yaml |
| 100 | +# and.example.3.dsc.config.yaml |
| 101 | +$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 102 | +resources: |
| 103 | + - name: Echo complex and operation |
| 104 | + type: Microsoft.DSC.Debug/Echo |
| 105 | + properties: |
| 106 | + output: "[and(equals(5, 5), equals('hello', 'hello'), true)]" |
| 107 | +``` |
| 108 | + |
| 109 | +```bash |
| 110 | +dsc config get --file and.example.3.dsc.config.yaml |
| 111 | +``` |
| 112 | + |
| 113 | +```yaml |
| 114 | +results: |
| 115 | +- metadata: |
| 116 | + Microsoft.DSC: |
| 117 | + duration: PT0.0514415S |
| 118 | + name: Echo complex and operation |
| 119 | + type: Microsoft.DSC.Debug/Echo |
| 120 | + result: |
| 121 | + actualState: |
| 122 | + output: true |
| 123 | +messages: [] |
| 124 | +hadErrors: false |
| 125 | +``` |
| 126 | + |
| 127 | +## Parameters |
| 128 | + |
| 129 | +### arguments |
| 130 | + |
| 131 | +The `and()` function requires two or more boolean arguments. |
| 132 | + |
| 133 | +```yaml |
| 134 | +Type: boolean |
| 135 | +Required: true |
| 136 | +MinimumCount: 2 |
| 137 | +MaximumCount: 18446744073709551615 |
| 138 | +``` |
| 139 | + |
| 140 | +## Output |
| 141 | + |
| 142 | +The `and()` function returns `true` if all arguments are `true`, otherwise it returns `false`. |
| 143 | + |
| 144 | +```yaml |
| 145 | +Type: boolean |
| 146 | +``` |
| 147 | + |
| 148 | +<!-- Link reference definitions --> |
0 commit comments