Skip to content

Commit 2f05566

Browse files
authored
Merge pull request #1351 from SteveL-MSFT/wu-resource
Add WindowsUpdate resource
2 parents b0b1416 + 103ff0d commit 2f05566

18 files changed

+2818
-4
lines changed

Cargo.lock

Lines changed: 64 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ members = [
1717
"resources/runcommandonset",
1818
"lib/dsc-lib-security_context",
1919
"resources/sshdconfig",
20+
"resources/WindowsUpdate",
2021
"tools/dsctest",
2122
"tools/test_group_resource",
2223
"grammars/tree-sitter-dscexpression",
@@ -41,6 +42,7 @@ default-members = [
4142
"resources/runcommandonset",
4243
"lib/dsc-lib-security_context",
4344
"resources/sshdconfig",
45+
"resources/WindowsUpdate",
4446
"tools/dsctest",
4547
"tools/test_group_resource",
4648
"grammars/tree-sitter-dscexpression",
@@ -67,6 +69,7 @@ Windows = [
6769
"resources/runcommandonset",
6870
"lib/dsc-lib-security_context",
6971
"resources/sshdconfig",
72+
"resources/WindowsUpdate",
7073
"tools/dsctest",
7174
"tools/test_group_resource",
7275
"grammars/tree-sitter-dscexpression",
@@ -219,6 +222,14 @@ urlencoding = { version = "2.1" }
219222
which = { version = "8.0" }
220223
# dsc-lib
221224
ipnetwork = { version = "0.21" }
225+
# WindowsUpdate
226+
windows = { version = "0.62", features = [
227+
"Win32_Foundation",
228+
"Win32_System_Com",
229+
"Win32_System_Ole",
230+
"Win32_System_Variant",
231+
"Win32_System_UpdateAgent"
232+
] }
222233

223234
# build-only dependencies
224235
# dsc-lib, dsc-lib-registry, sshdconfig, tree-sitter-dscexpression, tree-sitter-ssh-server-config

build.data.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
"sshd-windows.dsc.resource.json",
8383
"sshd_config.dsc.resource.json",
8484
"windowspowershell.dsc.resource.json",
85+
"windowsupdate.dsc.resource.json",
86+
"wu_dsc.exe",
8587
"wmi.dsc.resource.json",
8688
"wmi.resource.ps1",
8789
"wmiAdapter.psd1",
@@ -387,6 +389,21 @@
387389
]
388390
}
389391
},
392+
{
393+
"Name": "windowsupdate",
394+
"Kind": "Resource",
395+
"RelativePath": "resources/WindowsUpdate",
396+
"SupportedPlatformOS": "Windows",
397+
"IsRust": true,
398+
"Binaries": [
399+
"wu_dsc"
400+
],
401+
"CopyFiles": {
402+
"Windows": [
403+
"windowsupdate.dsc.resource.json"
404+
]
405+
}
406+
},
390407
{
391408
"Name": "dsctest",
392409
"Kind": "Resource",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"Name": "windowsupdate",
3+
"Kind": "Resource",
4+
"IsRust": true,
5+
"SupportedPlatformOS": "Windows",
6+
"Binaries": [
7+
"wu_dsc"
8+
],
9+
"CopyFiles": {
10+
"Windows": [
11+
"windowsupdate.dsc.resource.json"
12+
]
13+
}
14+
}

resources/WindowsUpdate/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "dsc-resource-windows-update"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[[bin]]
7+
name = "wu_dsc"
8+
path = "src/main.rs"
9+
10+
[dependencies]
11+
serde = { workspace = true }
12+
serde_json = { workspace = true }
13+
14+
[target.'cfg(windows)'.dependencies]
15+
windows = { workspace = true }

resources/WindowsUpdate/README.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Microsoft.Windows/UpdateList DSC Resource
2+
3+
## Overview
4+
5+
The `Microsoft.Windows/UpdateList` resource enables querying information about Windows Updates using the Windows Update Agent COM APIs. This resource allows you to retrieve detailed information about specific updates available on or installed on a Windows system.
6+
7+
## Features
8+
9+
- Query Windows Update information by title
10+
- Retrieve comprehensive update details including:
11+
- Installation status
12+
- Update description
13+
- Unique update identifier
14+
- KB article IDs
15+
- Recommended hard disk space
16+
- Security severity rating
17+
- Security bulletin IDs
18+
- Update type (Software or Driver)
19+
20+
## Requirements
21+
22+
- Windows operating system
23+
- Windows Update Agent (built into Windows)
24+
- Administrator privileges may be required for certain update queries
25+
26+
## Usage
27+
28+
### Get Operation
29+
30+
The `get` operation searches for a Windows Update by title or id (as exact match) and returns detailed information about the update.
31+
32+
#### Input Schema
33+
34+
```json
35+
{
36+
"updates": [{
37+
"title": "Security Update"
38+
}]
39+
}
40+
```
41+
42+
#### Example DSC Configuration
43+
44+
```yaml
45+
# windows-update-query.dsc.yaml
46+
$schema: https://aka.ms/dsc/schemas/v3/configuration.json
47+
resources:
48+
- name: QuerySecurityUpdate
49+
type: Microsoft.Windows/UpdateList
50+
properties:
51+
updates:
52+
- title: "Security Update for Windows"
53+
```
54+
55+
#### Output Example
56+
57+
```json
58+
{
59+
"updates": [{
60+
"title": "2024-01 Security Update for Windows 11 Version 22H2 for x64-based Systems (KB5034123)",
61+
"isInstalled": true,
62+
"description": "Install this update to resolve issues in Windows...",
63+
"id": "12345678-1234-1234-1234-123456789abc",
64+
"isUninstallable": true,
65+
"kbArticleIds": ["5034123"],
66+
"recommendedHardDiskSpace": 512,
67+
"msrcSeverity": "Critical",
68+
"securityBulletinIds": ["MS24-001"],
69+
"updateType": "Software"
70+
}]
71+
}
72+
```
73+
74+
## Properties
75+
76+
### Input/Output Properties
77+
78+
The resource returns an UpdateList object containing an array of updates:
79+
80+
| Property | Type | Description |
81+
|-----------------------|-----------------|-------------------------------------------------------|
82+
| updates | array | Array of update objects |
83+
| updates[].title | string | The full title of the Windows Update |
84+
| updates[].isInstalled | boolean | Whether the update is currently installed |
85+
| updates[].description | string | Detailed description of the update |
86+
| updates[].id | string | Unique identifier (GUID) for the update |
87+
| updates[].isUninstallable | boolean | Whether the update can be uninstalled |
88+
| updates[].kbArticleIds | array[string] | Knowledge Base article identifiers |
89+
| updates[].recommendedHardDiskSpace | integer (int64) | Recommended hard disk space in megabytes (MB) |
90+
| updates[].msrcSeverity | enum | MSRC severity: Critical, Important, Moderate, or Low |
91+
| updates[].securityBulletinIds | array[string] | Security bulletin identifiers |
92+
| updates[].updateType | enum | Type of update: Software or Driver |
93+
94+
## Implementation Details
95+
96+
- **Language**: Rust
97+
- **Executable**: `wu_dsc`
98+
- **COM APIs Used**: Windows Update Agent (WUA) COM interfaces
99+
- `IUpdateSession`
100+
- `IUpdateSearcher`
101+
- `IUpdateCollection`
102+
- `IUpdate`
103+
104+
## Limitations
105+
106+
- Requires Windows operating system
107+
- Search is case-insensitive and matches partial titles
108+
109+
## Building
110+
111+
To build the resource:
112+
113+
```powershell
114+
cd resources/WindowsUpdate
115+
cargo build --release
116+
```
117+
118+
The compiled executable will be located at `target/release/wu_dsc.exe`.
119+
120+
## Testing
121+
122+
To test the resource manually:
123+
124+
```powershell
125+
# Create input JSON
126+
$input = @{ updates = @(@{ title = "Security Update" }) } | ConvertTo-Json -Depth 3
127+
128+
# Query for an update
129+
$input | .\wu_dsc.exe get
130+
```
131+
132+
## Error Handling
133+
134+
The resource will return an error if:
135+
- No update matching the specified title is found
136+
- COM initialization fails
137+
- The Windows Update service is unavailable
138+
- Invalid input is provided
139+
140+
## License
141+
142+
Copyright (c) Microsoft Corporation.
143+
Licensed under the MIT License.

0 commit comments

Comments
 (0)