-
Notifications
You must be signed in to change notification settings - Fork 56
Reference doc null, createObject and coalesce #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
michaeltlombardi
merged 17 commits into
PowerShell:main
from
Gijsreyn:reference-doc-compare-and-object
Jul 30, 2025
Merged
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4e831bd
Initial setup coalesce doc
Gijsreyn eb87e54
Merge branch 'PowerShell:main' into reference-doc-compare-and-object
Gijsreyn 275a53e
Add null and createObject
Gijsreyn 4b3a3cb
Fix synopsis createArray
Gijsreyn 2246b39
Initial setup coalesce doc
Gijsreyn 5fa0998
Add null and createObject
Gijsreyn 27a5b1d
Fix synopsis createArray
Gijsreyn 85bdbcf
Merge branch 'reference-doc-compare-and-object' of https://github.com…
Gijsreyn 55dc25a
Resolve remarks Mikey
Gijsreyn 9136578
Initial setup coalesce doc
Gijsreyn 82b2fa2
Add null and createObject
Gijsreyn d6f5b03
Fix synopsis createArray
Gijsreyn 794ec7a
Initial setup coalesce doc
Gijsreyn 84e7966
Add null and createObject
Gijsreyn 9462687
Resolve remarks Mikey
Gijsreyn b9e62ea
Merge branch 'reference-doc-compare-and-object' of https://github.com…
Gijsreyn 9584cf4
Remove example
Gijsreyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| --- | ||
| description: Reference for the 'coalesce' DSC configuration document function | ||
| ms.date: 07/24/2025 | ||
| ms.topic: reference | ||
| title: coalesce | ||
| --- | ||
|
|
||
| # coalesce | ||
|
|
||
| ## Synopsis | ||
|
|
||
| Returns the first non-null value from a list of arguments. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```Syntax | ||
| coalesce(<value1>, <value2>, ...) | ||
| ``` | ||
|
|
||
| ## Description | ||
|
|
||
| The `coalesce()` function evaluates arguments from left to right and returns the first argument that | ||
| is not null. This function is useful for providing fallback values when dealing with potentially | ||
| null data. | ||
|
|
||
| If all arguments are null, the function returns null. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Example 1 - Basic coalesce with strings | ||
|
|
||
| The following example shows how to use the function with string values. | ||
|
|
||
| ```yaml | ||
| # coalesce.example.1.dsc.config.yaml | ||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| resources: | ||
| - name: Coalesce strings | ||
| type: Microsoft.DSC.Debug/Echo | ||
| properties: | ||
| output: | ||
| firstNonNull: "[coalesce(null(), 'DSC', 'landscape')]" | ||
| allNull: "[coalesce(null(), null(), null())]" | ||
| firstNotNull: "[coalesce('first', 'second', 'third')]" | ||
Gijsreyn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ```bash | ||
| dsc config get --file coalesce.example.1.dsc.config.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| results: | ||
| - name: Coalesce strings | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: | ||
| firstNonNull: DSC | ||
| allNull: null | ||
| firstNotNull: first | ||
Gijsreyn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| ### Example 2 - Mixed data types | ||
|
|
||
| The following example shows how the function works with different data types. | ||
|
|
||
| ```yaml | ||
| # coalesce.example.2.dsc.config.yaml | ||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| resources: | ||
| - name: Coalesce mixed types | ||
| type: Microsoft.DSC.Debug/Echo | ||
| properties: | ||
| output: | ||
| numberFallback: "[coalesce(null(), 42)]" | ||
| booleanFallback: "[coalesce(null(), null(), true)]" | ||
| stringToNumber: "[coalesce(null(), 123, 'fallback')]" | ||
| ``` | ||
|
|
||
| ```bash | ||
| dsc config get --file coalesce.example.2.dsc.config.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| results: | ||
| - name: Coalesce mixed types | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: | ||
| numberFallback: 42 | ||
| booleanFallback: true | ||
| stringToNumber: 123 | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| ### Example 3 - Configuration fallbacks | ||
|
|
||
| The following example shows a practical use case for providing configuration defaults. | ||
|
|
||
| ```yaml | ||
| # coalesce.example.3.dsc.config.yaml | ||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| parameters: | ||
| customValue: | ||
| type: string | ||
| defaultValue: 'customValue' | ||
| timeout: | ||
| type: int | ||
| defaultValue: 0 | ||
Gijsreyn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| resources: | ||
| - name: Configuration with fallbacks | ||
| type: Microsoft.DSC.Debug/Echo | ||
| properties: | ||
| output: | ||
| configValue: "[coalesce(parameters('customValue'), 'default-config')]" | ||
| timeout: "[coalesce(parameters('timeout'), 30)]" | ||
| ``` | ||
|
|
||
| ```bash | ||
| dsc config get --file coalesce.example.3.dsc.config.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| results: | ||
| - name: Configuration with fallbacks | ||
| type: Microsoft.DSC.Debug/Echo | ||
| result: | ||
| actualState: | ||
| output: | ||
| configValue: customValue | ||
| timeout: 0 | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| ### value1, value2 | ||
|
|
||
| The `coalesce()` function accepts one or more arguments of any type. | ||
| Arguments are evaluated from left to right, and the function returns the first non-null | ||
| value encountered. | ||
|
|
||
| ```yaml | ||
| Type: [any] | ||
| Required: true | ||
| MinimumCount: 1 | ||
| MaximumCount: unlimited | ||
| ``` | ||
|
|
||
| ## Output | ||
|
|
||
| The `coalesce()` function returns the first non-null argument, or null if all arguments are null. | ||
| The return type matches the type of the first non-null argument. | ||
|
|
||
| ```yaml | ||
| Type: [any] | ||
| ``` | ||
|
|
||
| ## Related functions | ||
|
|
||
| - [`null()`][00] - Returns a simple JSON null value. | ||
|
|
||
| <!-- Link reference definitions --> | ||
| [00]: ./null.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.