Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Synopsis
Returns the maximum value from a set of integers.
Syntax
max(<integerList>)
Description
The max()
function returns the maximum value from an array of integers or a comma-separated list
of integers.
Examples
Example 1 - Return maximum from a comma-separated list of integers
This configuration returns the largest number from a list of integers.
# max.example.1.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Echo maximum value
type: Test/Echo
properties:
output: "[max(3, 2, 5, 1, 7)]"
dsc config get --document max.example.1.dsc.config.yaml config get
results:
- name: Echo maximum value
type: Test/Echo
result:
actualState:
output: 7
messages: []
hadErrors: false
Example 2 - Return maximum from an array of integers
This configuration echoes the largest number from an array of integers that is retrieved as a reference to another resource instance. It uses YAML's folded multiline syntax to make the function more readable.
# max.example.2.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Echo integer array
type: Test/Echo
properties:
output:
- 3
- 2
- 5
- 1
- 7
- name: Echo maximum integer
type: Test/Echo
properties:
output: >-
[max(
reference(
resourceId('Test/Echo', 'Echo integer array')
).actualState.output
)]
dependsOn:
- "[resourceId('Test/Echo', 'Echo integer array')]"
dsc config get --document max.example.2.dsc.config.yaml
results:
- name: Echo integer array
type: Test/Echo
result:
actualState:
output:
- 3
- 2
- 5
- 1
- 7
- name: Echo maximum integer
type: Test/Echo
result:
actualState:
output: 7
Parameters
integerList
The max()
function expects either a single array of integers or a comma-separated array of
integers. When you pass integers directly, separate each integer with a comma. When you pass an
array object, the function only takes a single array as an argument.
Type: [integer, array(integer)]
Required: true
MinimumCount: 1
MaximumCount: 18446744073709551615
Output
The max()
function returns a single integer representing the largest value in the input.
Type: integer