22description : >
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
66ms.topic : reference
77title : Validate operating system information with dsc resource
88---
@@ -32,11 +32,10 @@ dsc resource get -r Microsoft/OSInfo
3232
3333``` yaml
3434actualState :
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
5150actualState :
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
6664actualState :
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
8078required. 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
8990This test checks whether the `family` property for the instance is `Linux`. It passes the desired
9091state 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
9899desiredState:
99- family: linux
100+ family: Linux
101+ version: '>= 20.04'
100102actualState:
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
124122desiredState:
125- family: Linux
126- bitness: '64'
123+ family: linux
127124actualState:
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
141139state 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
149147desiredState:
150148 family: macOS
149+ version: '>= 13.0'
151150actualState:
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
174169desiredState:
175170 family: MacOS
176- bitness: '64'
177171actualState:
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
198194desiredState:
199- family: windows
195+ family: Windows
196+ version: '>= 10.0'
200197actualState:
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
227218desiredState:
228- family: Windows
229- bitness: '64'
219+ family: windows
230220actualState:
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