|
| 1 | +--- |
| 2 | +description:> |
| 3 | + Example showing how to use the Microsoft.Windows/RebootPending resource in a |
| 4 | + configuration document with an assertion to check for a pending reboot. |
| 5 | +ms.date:03/25/2025 |
| 6 | +ms.topic:reference |
| 7 | +title:Use RebootPending resource in a configuration |
| 8 | +--- |
| 9 | + |
| 10 | +#Use the RebootPending resource in a configuration |
| 11 | + |
| 12 | +This example demonstrates how to use the`Microsoft.Windows/RebootPending` resource in a configuration document. |
| 13 | +The configuration checks if a reboot is pending and, if so, skips the subsequent step using an assertion. |
| 14 | + |
| 15 | +##Definition |
| 16 | + |
| 17 | +This configuration document demonstrates how to use the`Microsoft.Windows/RebootPending` resource together with an assertion. |
| 18 | + |
| 19 | +The first instance defines the desired state for the`ManagedKey` registry key, ensuring it |
| 20 | +exists only if no reboot is pending. It uses the`dependsOn` property to reference the assertion resource, |
| 21 | +which checks the system's reboot status using the`Microsoft.Windows/RebootPending` resource. |
| 22 | +The assertion passes when`rebootPending` is`false`,allowing the registry key resource to run. |
| 23 | +If a reboot is pending, the assertion fails and the registry key is not set. |
| 24 | + |
| 25 | +:::code language="yaml" source="pendingReboot.config.dsc.yaml"::: |
| 26 | + |
| 27 | +Copy the configuration document and save it as`pendingReboot.config.dsc.yaml`. |
| 28 | + |
| 29 | +##Test configuration |
| 30 | + |
| 31 | +To see whether the system is in the desired state, use the[dsc config test][01] command on the |
| 32 | +configuration document. |
| 33 | + |
| 34 | +```powershell |
| 35 | +dsc config test --file ./pendingReboot.config.dsc.yaml |
| 36 | +``` |
| 37 | + |
| 38 | +```yaml |
| 39 | +metadata: |
| 40 | +Microsoft.DSC: |
| 41 | +version:3.0.0 |
| 42 | +operation:test |
| 43 | +executionType:actual |
| 44 | +startDatetime:2025-06-03T06:49:22.573486200+02:00 |
| 45 | +endDatetime:2025-06-03T06:49:35.813770500+02:00 |
| 46 | +duration:PT13.2402843S |
| 47 | +securityContext:restricted |
| 48 | +results: |
| 49 | +-metadata: |
| 50 | +Microsoft.DSC: |
| 51 | +duration:PT10.0162818S |
| 52 | +name:Assert pending reboot |
| 53 | +type:Microsoft.DSC/Assertion |
| 54 | +result: |
| 55 | +desiredState: |
| 56 | +$schema:https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 57 | +resources: |
| 58 | + -name:Check pending reboot |
| 59 | +type:Microsoft.Windows/RebootPending |
| 60 | +properties: |
| 61 | +rebootPending:false |
| 62 | +actualState: |
| 63 | +$schema:https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 64 | +contentVersion:1.0.0 |
| 65 | +resources: |
| 66 | + -type:Microsoft.Windows/RebootPending |
| 67 | +name:Check pending reboot |
| 68 | +properties: |
| 69 | +rebootPending:false |
| 70 | +inDesiredState:true |
| 71 | +differingProperties:[] |
| 72 | +-metadata: |
| 73 | +Microsoft.DSC: |
| 74 | +duration:PT0.0549784S |
| 75 | +name:Managed key |
| 76 | +type:Microsoft.Windows/Registry |
| 77 | +result: |
| 78 | +desiredState: |
| 79 | +_exist:true |
| 80 | +keyPath:HKCU\DscExamples\ManagedKey |
| 81 | +actualState: |
| 82 | +keyPath:HKCU\DscExamples\ManagedKey |
| 83 | +_exist:false |
| 84 | +inDesiredState:false |
| 85 | +differingProperties: |
| 86 | + -_exist |
| 87 | +messages:[] |
| 88 | +hadErrors:false |
| 89 | +``` |
| 90 | +
|
| 91 | +Review the individual results to understand whether each instance is in the desired state. |
| 92 | +
|
| 93 | +The result for the first instance, named`Check pending reboot`, was: |
| 94 | + |
| 95 | +```yaml |
| 96 | +desiredState: |
| 97 | + $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 98 | + resources: |
| 99 | + - name: Check pending reboot |
| 100 | + type: Microsoft.Windows/RebootPending |
| 101 | + properties: |
| 102 | + rebootPending: false |
| 103 | +actualState: |
| 104 | + $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 105 | + contentVersion: 1.0.0 |
| 106 | + resources: |
| 107 | + - type: Microsoft.Windows/RebootPending |
| 108 | + name: Check pending reboot |
| 109 | + properties: |
| 110 | + rebootPending: false |
| 111 | +inDesiredState: true |
| 112 | +differingProperties: [] |
| 113 | +``` |
| 114 | + |
| 115 | +The output indicates there is no pending reboot. When you use the **Set** operation on |
| 116 | +this confifguration, the second instance will run. |
| 117 | + |
| 118 | +The result for the second instance, named `Managed value`, was: |
| 119 | + |
| 120 | +```yaml |
| 121 | +desiredState: |
| 122 | + _exist: true |
| 123 | + keyPath: HKCU\DscExamples\ManagedKey |
| 124 | +actualState: |
| 125 | + keyPath: HKCU\DscExamples\ManagedKey |
| 126 | + _exist: false |
| 127 | +inDesiredState: false |
| 128 | +differingProperties: |
| 129 | +- _exist |
| 130 | +``` |
| 131 | + |
| 132 | +The output indicates the registry path doesn't exist. |
| 133 | + |
| 134 | +The first instance indicates the resource is in the desired state. The second |
| 135 | +instance indicates it isn't in the desired state. |
| 136 | + |
| 137 | +## Enforce configuration |
| 138 | + |
| 139 | +To update the system to the desired state, use the [dsc config set][02] command on the configuration document. |
| 140 | + |
| 141 | +```powershell |
| 142 | +dsc config set --file ./pendingReboot.config.dsc.yaml |
| 143 | +``` |
| 144 | + |
| 145 | +```yaml |
| 146 | +metadata: |
| 147 | + Microsoft.DSC: |
| 148 | + version: 3.0.0 |
| 149 | + operation: set |
| 150 | + executionType: actual |
| 151 | + startDatetime: 2025-06-03T06:55:12.123456+02:00 |
| 152 | + endDatetime: 2025-06-03T06:55:15.654321+02:00 |
| 153 | + duration: PT3.530865S |
| 154 | + securityContext: restricted |
| 155 | +results: |
| 156 | +- metadata: |
| 157 | + Microsoft.DSC: |
| 158 | + duration: PT2.000000S |
| 159 | + name: Assert pending reboot |
| 160 | + type: Microsoft.DSC/Assertion |
| 161 | + result: |
| 162 | + beforeState: |
| 163 | + $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 164 | + resources: |
| 165 | + - name: Check pending reboot |
| 166 | + type: Microsoft.Windows/RebootPending |
| 167 | + properties: |
| 168 | + rebootPending: false |
| 169 | + afterState: |
| 170 | + $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 171 | + resources: |
| 172 | + - name: Check pending reboot |
| 173 | + type: Microsoft.Windows/RebootPending |
| 174 | + properties: |
| 175 | + rebootPending: false |
| 176 | + changedProperties: [] |
| 177 | +- metadata: |
| 178 | + Microsoft.DSC: |
| 179 | + duration: PT0.0549784S |
| 180 | + name: Managed key |
| 181 | + type: Microsoft.Windows/Registry |
| 182 | + result: |
| 183 | + beforeState: |
| 184 | + keyPath: HKCU\DscExamples\ManagedKey |
| 185 | + _exist: false |
| 186 | + afterState: |
| 187 | + keyPath: HKCU\DscExamples\ManagedKey |
| 188 | + changedProperties: |
| 189 | + - _exist |
| 190 | +messages: [] |
| 191 | +hadErrors: false |
| 192 | +``` |
| 193 | + |
| 194 | +Review the individual results to understand how the resource modified the system to enforce the desired state for each instance. |
| 195 | + |
| 196 | +The result for the assertion instance, named `Assert pending reboot`, was: |
| 197 | + |
| 198 | +```yaml |
| 199 | +beforeState: |
| 200 | +- name: Check pending reboot |
| 201 | + type: Microsoft.Windows/RebootPending |
| 202 | + result: |
| 203 | + actualState: |
| 204 | + rebootPending: false |
| 205 | +afterState: |
| 206 | +- metadata: |
| 207 | + Microsoft.DSC: |
| 208 | + duration: PT0.5209322S |
| 209 | + name: Check pending reboot |
| 210 | + type: Microsoft.Windows/RebootPending |
| 211 | + result: |
| 212 | + desiredState: |
| 213 | + rebootPending: false |
| 214 | + actualState: |
| 215 | + rebootPending: false |
| 216 | + inDesiredState: true |
| 217 | + differingProperties: [] |
| 218 | +changedProperties: [] |
| 219 | +``` |
| 220 | + |
| 221 | +The output indicates the assertion passed and no changes were needed. |
| 222 | + |
| 223 | +The result for the registry key instance, named `Managed key`, was: |
| 224 | + |
| 225 | +```yaml |
| 226 | +beforeState: |
| 227 | + keyPath: HKCU\DscExamples\ManagedKey |
| 228 | + _exist: false |
| 229 | +afterState: |
| 230 | + keyPath: HKCU\DscExamples\ManagedKey |
| 231 | +changedProperties: |
| 232 | +- _exist |
| 233 | +``` |
| 234 | + |
| 235 | +The output indicates that the resource created the registry key. |
| 236 | + |
| 237 | +## Cleanup |
| 238 | + |
| 239 | +To return your system to its original state: |
| 240 | + |
| 241 | +1. Save the following configuration as `registry.cleanup.config.dsc.yaml`. |
| 242 | + |
| 243 | +:::code language="yaml" source="../../Registry/examples/registry.cleanup.config.dsc.yaml"::: |
| 244 | + |
| 245 | +2. Use the **Set** operation on the cleanup configuration document. |
| 246 | + |
| 247 | +```powershell |
| 248 | + dsc config set --file ./registry.cleanup.config.dsc.yaml |
| 249 | +``` |
| 250 | + |
| 251 | +<!-- Link reference definitions --> |
| 252 | +[01]:../../../../../cli/config/test.md |
| 253 | +[02]:../../../../../cli/config/set.md |