Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions docs/reference/schemas/config/functions/endsWith.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
---
description: Reference for the 'endsWith' DSC configuration document function
ms.date: 08/12/2025
ms.topic: reference
title: endsWith
---

# endsWith

## Synopsis

Determines whether a string ends with the specified suffix.

## Syntax

```Syntax
endsWith(<string>, <suffix>)
```

## Description

The `endsWith()` function returns `true` if the first string ends with the
specified suffix. Comparison is case-sensitive. Use it for conditional logic in
configuration documents such as matching file extensions, environment name
suffixes, or resource identifiers.

## Examples

### Example 1 - Check a file extension

The following example checks if a specified filename ends with `.log`.

```yaml
# endswith.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
fileName:
type: string
defaultValue: application.log
resources:
- name: Check file extension
type: Microsoft.DSC.Debug/Echo
properties:
output:
isLog: "[endsWith(parameters('fileName'), '.log')]"
```

```bash
dsc config get --file endswith.example.1.dsc.config.yaml
```

```yaml
results:
- name: Check file extension
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
isLog: true
messages: []
hadErrors: false
```

### Example 2 - Conditional environment handling

The following example uses `endsWith()` to build a message when an environment
name ends with `-prod`.

```yaml
# endswith.example.2.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
environment:
type: string
defaultValue: web-prod
resources:
- name: Environment classification
type: Microsoft.DSC.Debug/Echo
properties:
output:
classification: "[if(endsWith(parameters('environment'), '-prod'), 'Production', 'Non-production')]"
```

```bash
dsc config get --file endswith.example.2.dsc.config.yaml
```

```yaml
results:
- name: Environment classification
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
classification: Production
messages: []
hadErrors: false
```

### Example 3 - Filter resource identifiers

The following example shows checking multiple suffixes by combining conditions.

```yaml
# endswith.example.3.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
resourceId:
type: string
defaultValue: storage-westus-01
resources:
- name: Identify resource segment
type: Microsoft.DSC.Debug/Echo
properties:
output:
isRegional: "[endsWith(parameters('resourceId'), '-01')]"
endsWithWest: "[endsWith(parameters('resourceId'), 'westus-01')]"
endsWithEast: "[endsWith(parameters('resourceId'), 'eastus-01')]"
```

```bash
dsc config get --file endswith.example.3.dsc.config.yaml
```

```yaml
results:
- name: Identify resource segment
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
isRegional: true
endsWithWest: true
endsWithEast: false
messages: []
hadErrors: false
```

## Parameters

### string

The input string to evaluate.

```yaml
Type: string
Required: true
Position: 1
```

### suffix

The suffix string to test for.

```yaml
Type: string
Required: true
Position: 2
```

## Output

The `endsWith()` function returns a boolean value indicating whether the input
string ends with the specified suffix.

```yaml
Type: bool
```

## Related functions

- [`startsWith()`][00] - Determines whether a string starts with a prefix
- [`concat()`][01] - Concatenates strings together
- [`if()`][02] - Returns values based on a condition
- [`string()`][03] - Converts values to strings

<!-- Link reference definitions -->
[00]: ./startsWith.md
[01]: ./concat.md
[02]: ./if.md
[03]: ./string.md
181 changes: 181 additions & 0 deletions docs/reference/schemas/config/functions/startsWith.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
---
description: Reference for the 'startsWith' DSC configuration document function
ms.date: 08/12/2025
ms.topic: reference
title: startsWith
---

# startsWith

## Synopsis

Determines whether a string starts with the specified prefix.

## Syntax

```Syntax
startsWith(<string>, <prefix>)
```

## Description

The `startsWith()` function returns `true` if the first string starts with the
specified prefix. Comparison is case-sensitive. Use it for conditional logic in
configuration documents such as grouping resource names, validating identifiers,
or routing operations based on naming conventions.

## Examples

### Example 1 - Validate resource naming convention

The following example checks if a resource name follows a standard prefix.

```yaml
# startswith.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
resourceName:
type: string
defaultValue: svc-api-west
resources:
- name: Resource naming check
type: Microsoft.DSC.Debug/Echo
properties:
output:
hasSvcPrefix: "[startsWith(parameters('resourceName'), 'svc-')]"
```

```bash
dsc config get --file startswith.example.1.dsc.config.yaml
```

```yaml
results:
- name: Resource naming check
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
hasSvcPrefix: true
messages: []
hadErrors: false
```

### Example 2 - Conditional routing

The following example shows using `startsWith()` with `if()` to categorize a
service by its name prefix.

```yaml
# startswith.example.2.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
serviceName:
type: string
defaultValue: api-orders
resources:
- name: Service classification
type: Microsoft.DSC.Debug/Echo
properties:
output:
classification: "[if(startsWith(parameters('serviceName'), 'api-'), 'API Service', 'Other Service')]"
```

```bash
dsc config get --file startswith.example.2.dsc.config.yaml
```

```yaml
results:
- name: Service classification
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
classification: API Service
messages: []
hadErrors: false
```

### Example 3 - Multi-prefix evaluation

The following example evaluates multiple possible prefixes.

```yaml
# startswith.example.3.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
name:
type: string
defaultValue: db-primary-01
resources:
- name: Prefix grouping
type: Microsoft.DSC.Debug/Echo
properties:
output:
isDb: "[startsWith(parameters('name'), 'db-')]"
isApi: "[startsWith(parameters('name'), 'api-')]"
isCache: "[startsWith(parameters('name'), 'cache-')]"
```

```bash
dsc config get --file startswith.example.3.dsc.config.yaml
```

```yaml
results:
- name: Prefix grouping
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
isDb: true
isApi: false
isCache: false
messages: []
hadErrors: false
```

## Parameters

### string

The input string to evaluate.

```yaml
Type: string
Required: true
Position: 1
```

### prefix

The prefix string to test for.

```yaml
Type: string
Required: true
Position: 2
```

## Output

The `startsWith()` function returns a boolean value indicating whether the
input string starts with the specified prefix.

```yaml
Type: bool
```

## Related functions

- [`endsWith()`][00] - Determines whether a string ends with a suffix
- [`concat()`][01] - Concatenates strings together
- [`if()`][02] - Returns values based on a condition
- [`string()`][03] - Converts values to strings

<!-- Link reference definitions -->
[00]: ./endsWith.md
[01]: ./concat.md
[02]: ./if.md
[03]: ./string.md
Loading