Skip to content

Commit ea69c5b

Browse files
Merge pull request #1623 from Gijsreyn/gh-1603/main/update-osinfo-docs
docs: add examples for validating minimum operating system version with `Microsoft/OSInfo`
2 parents 4412cac + 68367c1 commit ea69c5b

4 files changed

Lines changed: 196 additions & 98 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# yaml-language-server: $schema=https://aka.ms/dsc/schemas/v3/bundled/config/document.vscode.json
2+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
3+
resources:
4+
- name: Operating System Assertion
5+
type: Microsoft.DSC/Assertion
6+
properties:
7+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
8+
resources:
9+
- name: Minimum operating system version
10+
type: Microsoft/OSInfo
11+
properties:
12+
version: '>= 10.0'
13+
- name: Show operating system
14+
type: Microsoft.DSC.Debug/Echo
15+
properties:
16+
output: 'The operating system meets the minimum version requirement.'
17+
dependsOn:
18+
- "[resourceId('Microsoft.DSC/Assertion', 'Operating System Assertion')]"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
description: Validate a minimum operating system version with Microsoft/OSInfo
3+
ms.date: 07/11/2026
4+
ms.topic: reference
5+
title: Validate a minimum operating system version
6+
---
7+
8+
# Validate a minimum operating system version
9+
10+
This example uses the `Microsoft/OSInfo` resource with the `Microsoft.DSC/Assertion` group
11+
resource to verify that the operating system version meets a minimum requirement before DSC runs
12+
another resource.
13+
14+
> [!IMPORTANT]
15+
> The `osinfo` command and `Microsoft/OSInfo` resource are a proof-of-concept example for use with
16+
> DSC. Don't use it in production.
17+
18+
## Definition
19+
20+
The **Operating System Assertion** group contains a `Microsoft/OSInfo` resource instance with the
21+
version constraint `>= 10.0`. The `Microsoft.DSC/Assertion` resource always invokes **Test** for
22+
nested instances. If the operating system is earlier than version `10.0`, the configuration fails
23+
and DSC doesn't invoke **Show operating system**.
24+
25+
:::code language="yaml" source="validate-minimum-version.config.dsc.yaml":::
26+
27+
## Running the configuration
28+
29+
Run the configuration with the [dsc config set][01] command:
30+
31+
```bash
32+
dsc config set --file ./validate-minimum-version.config.dsc.yaml
33+
```
34+
35+
On an operating system whose version is at least `10.0`, DSC returns successful results for both
36+
the assertion group and the dependent echo resource:
37+
38+
```yaml
39+
results:
40+
- name: Operating System Assertion
41+
type: Microsoft.DSC/Assertion
42+
result:
43+
beforeState:
44+
- name: Minimum operating system version
45+
type: Microsoft/OSInfo
46+
result:
47+
actualState:
48+
family: Windows
49+
version: 10.0.26200
50+
_inDesiredState: true
51+
afterState:
52+
- name: Minimum operating system version
53+
type: Microsoft/OSInfo
54+
result:
55+
desiredState:
56+
version: '>= 10.0'
57+
actualState:
58+
family: Windows
59+
version: 10.0.26200
60+
edition: Windows 11
61+
bitness: 64
62+
architecture: x86_64
63+
_inDesiredState: true
64+
inDesiredState: true
65+
differingProperties:
66+
- version
67+
changedProperties: []
68+
- name: Show operating system
69+
type: Microsoft.DSC.Debug/Echo
70+
result:
71+
beforeState:
72+
output: The operating system meets the minimum version requirement.
73+
afterState:
74+
output: The operating system meets the minimum version requirement.
75+
changedProperties: null
76+
messages: []
77+
hadErrors: false
78+
```
79+
80+
<!-- Link references -->
81+
[01]: ../../../../cli/config/set.md

docs/reference/resources/Microsoft/OSInfo/examples/validate-with-dsc-resource.md

Lines changed: 73 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: >
33
Validate operating system information with the Microsoft/OSInfo DSC Resource
44
and the dsc resource commands.
5-
ms.date: 03/25/2025
5+
ms.date: 07/12/2026
66
ms.topic: reference
77
title: Validate operating system information with dsc resource
88
---
@@ -32,11 +32,10 @@ dsc resource get -r Microsoft/OSInfo
3232

3333
```yaml
3434
actualState:
35-
$id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
3635
family: Linux
3736
version: '20.04'
3837
codename: focal
39-
bitness: '64'
38+
bitness: 64
4039
architecture: x86_64
4140
```
4241
@@ -49,10 +48,9 @@ dsc resource get -r Microsoft/OSInfo
4948

5049
```yaml
5150
actualState:
52-
$id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
53-
family: MacOS
51+
family: macOS
5452
version: 13.5.0
55-
bitness: '64'
53+
bitness: 64
5654
architecture: arm64
5755
```
5856
@@ -64,11 +62,11 @@ dsc resource get --resource Microsoft/OSInfo
6462

6563
```yaml
6664
actualState:
67-
$id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
6865
family: Windows
6966
version: 10.0.22621
7067
edition: Windows 11 Enterprise
71-
bitness: '64'
68+
bitness: 64
69+
architecture: x86_64
7270
```
7371
7472
---
@@ -79,60 +77,60 @@ DSC can use the resource to validate the operating system information. When you
7977
[dsc resource test][02] command, input JSON representing the desired state of the instance is
8078
required. The JSON must define at least one instance property to validate.
8179
82-
The resource doesn't implement the [test operation][03]. It relies on the synthetic testing feature
83-
of DSC instead. The synthetic test uses a case-sensitive equivalency comparison between the actual
84-
state of the instance properties and the desired state. If any property value isn't an exact match,
85-
DSC considers the instance to be out of the desired state.
80+
The resource implements the [test operation][03]. The command passes the desired state to the
81+
resource over stdin and the resource returns the actual operating system information with an
82+
`_inDesiredState` value. DSC returns that value as `inDesiredState` in the test result.
83+
84+
All properties except `version` use case-sensitive equality comparison. For `version`, you can use
85+
an exact version or a constraint with `>`, `<`, `=`, `>=`, or `<=`. For more information, see the
86+
[version property][04] reference.
8687

8788
# [Linux](#tab/linux)
8889

8990
This test checks whether the `family` property for the instance is `Linux`. It passes the desired
9091
state for the instance to the command from stdin with the `--file` (`-f`) option.
9192

9293
```bash
93-
invalid_instance='{"family": "Linux"}'
94-
echo $invalid_instance | dsc resource test -r "${resource}" -f -
94+
valid_instance='{"family": "Linux", "version": ">= 20.04"}'
95+
echo $valid_instance | dsc resource test -r Microsoft/OSInfo -f -
9596
```
9697

9798
```yaml
9899
desiredState:
99-
family: linux
100+
family: Linux
101+
version: '>= 20.04'
100102
actualState:
101-
$id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
102103
family: Linux
103104
version: '20.04'
104105
codename: focal
105-
bitness: '64'
106+
bitness: 64
106107
architecture: x86_64
107-
inDesiredState: false
108-
differingProperties:
109-
- family
108+
_inDesiredState: true
109+
inDesiredState: true
110+
differingProperties: []
110111
```
111112

112-
The result shows that the resource is out of the desired state because the actual state of the
113-
`family` property wasn't case-sensitively equal to the desired state.
114-
115-
The next test validates that the operating system is a 64-bit Linux operating system. It passes
116-
the desired state for the instance to the command with the `--input` (`-i`) option.
113+
The result shows that the resource evaluated both the family and version constraint successfully.
114+
The next test demonstrates a case-sensitive mismatch.
117115

118116
```bash
119-
valid_instance='{ "family": "Linux", "bitness": "64" }'
120-
echo $valid_instance | dsc resource test -r Microsoft/OSInfo -i $valid_instance
117+
invalid_instance='{ "family": "linux" }'
118+
dsc resource test -r Microsoft/OSInfo -i $invalid_instance
121119
```
122120

123121
```yaml
124122
desiredState:
125-
family: Linux
126-
bitness: '64'
123+
family: linux
127124
actualState:
128-
$id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
129125
family: Linux
130126
version: '20.04'
131127
codename: focal
132-
bitness: '64'
128+
bitness: 64
133129
architecture: x86_64
134-
inDesiredState: true
135-
differingProperties: []
130+
_inDesiredState: false
131+
inDesiredState: false
132+
differingProperties:
133+
- family
136134
```
137135

138136
# [macOS](#tab/macos)
@@ -141,100 +139,94 @@ This test checks whether the `family` property for the instance is `macOS`. It p
141139
state for the instance to the command from stdin with the `--file` (`-f`) option.
142140

143141
```zsh
144-
invalid_instance='{"family": "macOS"}'
145-
echo $invalid_instance | dsc resource test -r Microsoft/OSInfo -f -
142+
valid_instance='{"family": "macOS", "version": ">= 13.0"}'
143+
echo $valid_instance | dsc resource test -r Microsoft/OSInfo -f -
146144
```
147145

148146
```yaml
149147
desiredState:
150148
family: macOS
149+
version: '>= 13.0'
151150
actualState:
152-
$id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
153-
family: MacOS
151+
family: macOS
154152
version: 13.5.0
155-
bitness: '64'
153+
bitness: 64
156154
architecture: arm64
157-
inDesiredState: false
158-
differingProperties:
159-
- family
155+
_inDesiredState: true
156+
inDesiredState: true
157+
differingProperties: []
160158
```
161159

162-
The result shows that the resource is out of the desired state because the actual state of the
163-
`family` property wasn't case-sensitively equal to the desired state.
164-
165-
The next test validates that the operating system is a 64-bit macOS operating system. It passes the
166-
desired state for the instance to the command with the `--input` (`-i`) option.
160+
The result shows that the resource evaluates the version constraint in addition to the family.
161+
The next test demonstrates a case-sensitive mismatch.
167162

168163
```zsh
169-
valid_instance='{ "family": "MacOS", "bitness": "64" }'
170-
dsc resource test -r Microsoft/OSInfo -i $valid_instance
164+
invalid_instance='{ "family": "MacOS" }'
165+
dsc resource test -r Microsoft/OSInfo -i $invalid_instance
171166
```
172167

173168
```yaml
174169
desiredState:
175170
family: MacOS
176-
bitness: '64'
177171
actualState:
178-
$id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
179-
family: MacOS
172+
family: macOS
180173
version: 13.5.0
181-
bitness: '64'
174+
bitness: 64
182175
architecture: arm64
183-
inDesiredState: true
184-
differingProperties: []
176+
_inDesiredState: false
177+
inDesiredState: false
178+
differingProperties:
179+
- family
185180
```
186181

187182
# [Windows](#tab/windows)
188183

189-
This test checks whether the `family` property for the instance is `windows`. It passes the desired
190-
state for the instance to the command from stdin with the `--file` (`-f`) option.
184+
This test checks whether the `family` property for the instance is `Windows` and whether the
185+
operating system version is at least `10.0`. It passes the desired state for the instance to the
186+
command from stdin with the `--file` (`-f`) option.
191187

192188
```powershell
193-
$invalidInstance = @{ family = 'windows' } | ConvertTo-JSON
194-
$invalidInstance | dsc resource test --resource Microsoft/OSInfo --file -
189+
$validInstance = @{ family = 'Windows'; version = '>= 10.0' } | ConvertTo-JSON
190+
$validInstance | dsc resource test --resource Microsoft/OSInfo --file -
195191
```
196192

197193
```yaml
198194
desiredState:
199-
family: windows
195+
family: Windows
196+
version: '>= 10.0'
200197
actualState:
201-
$id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
202198
family: Windows
203199
version: 10.0.22621
204200
edition: Windows 11 Enterprise
205-
bitness: "64"
206-
inDesiredState: false
207-
differingProperties:
208-
- family
201+
bitness: 64
202+
architecture: x86_64
203+
_inDesiredState: true
204+
inDesiredState: true
205+
differingProperties: []
209206
```
210207

211-
The result shows that the resource is out of the desired state because the actual state of the
212-
`family` property wasn't case-sensitively equal to the desired state.
213-
214-
The next test validates that the operating system is a 64-bit Windows operating system. It passes
215-
the desired state for the instance to the command with the `--input` (`-i`) option.
208+
The result shows that the resource evaluated both the family and version constraint successfully.
209+
The next test demonstrates a case-sensitive mismatch.
216210

217211
```powershell
218-
$validInstance = @{
219-
family = 'Windows'
220-
bitness = '64'
221-
} | ConvertTo-JSON
212+
$invalidInstance = @{ family = 'windows' } | ConvertTo-JSON
222213
223-
dsc resource test --resource Microsoft/OSInfo --input $validInstance
214+
dsc resource test --resource Microsoft/OSInfo --input $invalidInstance
224215
```
225216

226217
```yaml
227218
desiredState:
228-
family: Windows
229-
bitness: '64'
219+
family: windows
230220
actualState:
231-
$id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
232221
family: Windows
233222
version: 10.0.22621
234223
edition: Windows 11 Enterprise
235-
bitness: "64"
236-
inDesiredState: true
237-
differingProperties: []
224+
bitness: 64
225+
architecture: x86_64
226+
_inDesiredState: false
227+
inDesiredState: false
228+
differingProperties:
229+
- family
238230
```
239231

240232
---
@@ -243,3 +235,4 @@ differingProperties: []
243235
[01]: ../../../../cli/resource/get.md
244236
[02]: ../../../../cli/resource/test.md
245237
[03]: ../../../../../concepts/resources/overview.md#test-operations
238+
[04]: ../index.md#version

0 commit comments

Comments
 (0)