|
| 1 | +--- |
| 2 | +description: Microsoft.Windows/WMI resource adapter reference documentation |
| 3 | +ms.date: 03/25/2025 |
| 4 | +ms.topic: reference |
| 5 | +title: Microsoft.Windows/WMI |
| 6 | +--- |
| 7 | + |
| 8 | +# Microsoft.Windows/WMI |
| 9 | + |
| 10 | +## Synopsis |
| 11 | + |
| 12 | +Adapter for querying and retrieving information from Windows Management Instrumentation (WMI). |
| 13 | + |
| 14 | +## Metadata |
| 15 | + |
| 16 | +```yaml |
| 17 | +Version : 0.1.0 |
| 18 | +Kind : resource |
| 19 | +Tags : [windows, wmi] |
| 20 | +Author : Microsoft |
| 21 | +``` |
| 22 | +
|
| 23 | +## Instance definition syntax |
| 24 | +
|
| 25 | +```yaml |
| 26 | +resources: |
| 27 | + - name: <instanceName> |
| 28 | + type: Microsoft.Windows/WMI |
| 29 | + properties: |
| 30 | + # Required properties |
| 31 | + resources: |
| 32 | + - name: <nested instance name> |
| 33 | + type: <namespace name>/<class name> |
| 34 | + properties: # adapted resource properties |
| 35 | + |
| 36 | +# Or from v3.1.0-preview.2 onwards |
| 37 | +resources: |
| 38 | +- name: <instanceName> |
| 39 | + type: <namespace name>/<class name> |
| 40 | + properties: # adapted resource properties |
| 41 | + |
| 42 | +``` |
| 43 | + |
| 44 | +## Description |
| 45 | + |
| 46 | +The `Microsoft.Windows/WMI` resource adapter enables you to query and retrieve information |
| 47 | +from Windows Management Instrumentation (WMI). The resource can: |
| 48 | + |
| 49 | +- Execute WMI queries to retrieve system information |
| 50 | +- Filter WMI query results based on specific conditions |
| 51 | +- Access data from different WMI namespaces |
| 52 | + |
| 53 | +The adapter leverages PowerShell commands to retrieve and list information of WMI classes. |
| 54 | + |
| 55 | +## Requirements |
| 56 | + |
| 57 | +- The resource is only usable on a Windows system. |
| 58 | +- The resource must run in a process context that has appropriate permissions to access WMI. |
| 59 | + |
| 60 | +## Capabilities |
| 61 | + |
| 62 | +The resource adapter has the following capabilities: |
| 63 | + |
| 64 | +- `get` - You can use the resource to retrieve information from WMI. |
| 65 | +- `list` - Lists available WMI classes that can be queried. |
| 66 | + |
| 67 | +## Examples |
| 68 | + |
| 69 | +1. [Query Operating System Information][01] - Shows how to query basic operating system information |
| 70 | +2. [Query Filtered Disk Information][02] - Shows how to query disk drives with filtering |
| 71 | + |
| 72 | +## Properties |
| 73 | + |
| 74 | +## Property schema |
| 75 | + |
| 76 | +WMI properties aren't exposed directly to a schema. To discover the available properties for a WMI class that you |
| 77 | +can use in your configuration, run the following PowerShell command: |
| 78 | + |
| 79 | +```powershell |
| 80 | +dsc resource list --adapter Microsoft.Windows/WMI <namespace name>/<class name> | |
| 81 | + ConvertFrom-Json | |
| 82 | + Select-Object properties |
| 83 | +``` |
| 84 | + |
| 85 | +When defining a configuration document, the following properties are required. |
| 86 | + |
| 87 | +### resources |
| 88 | + |
| 89 | +The `resources` property defines a list of adapted WMI class instances that the adapter manages. |
| 90 | +Every instance in the list must be unique, but instances may share the same DSC resource type. |
| 91 | + |
| 92 | +For more information about defining a valid adapted resource instance, see the |
| 93 | +[Adapted resource instances](#adapted-resource-instances) section of this document. |
| 94 | + |
| 95 | +```yaml |
| 96 | +Type: array |
| 97 | +Required: true |
| 98 | +MinimumItemCount: 1 |
| 99 | +ValidItemSchema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/v3.0.0/config/document.resource.json |
| 100 | +``` |
| 101 | +
|
| 102 | +## Adapted resource instances |
| 103 | +
|
| 104 | +Adapted resources instances always adhere to the |
| 105 | +[DSC Configuration document resource instance schema](../../../../schemas/config/resource.md). |
| 106 | +
|
| 107 | +Every adapted instance must be an object that defines the [name](#adapted-instance-name), |
| 108 | +[type](#adapted-instance-type), and [properties](#adapted-instance-properties) for the instance. |
| 109 | +
|
| 110 | +### Adapted instance name |
| 111 | +
|
| 112 | +The `name` property of the adapted resource instance defines the short, human-readable name for the |
| 113 | +instance. The adapted instance name must be a non-empty string containing only letters, numbers, |
| 114 | +and spaces. This property should be unique within the adapter's `resources` array. |
| 115 | + |
| 116 | +> ![NOTE] |
| 117 | +> The adapter doesn't currently raise an error when you define two adapted instances with the same |
| 118 | +> name. In a future release, the adapter will be updated to emit a warning when adapted instances |
| 119 | +> share the same name. In the next major version of the adapter, name conflicts will raise an |
| 120 | +> error. |
| 121 | +> |
| 122 | +> Using the same name for multiple instances can make debugging and reviewing output more |
| 123 | +> difficult. Always use unique names for every instance. |
| 124 | + |
| 125 | +```yaml |
| 126 | +PropertyName: name |
| 127 | +Type: string |
| 128 | +Required: true |
| 129 | +MinimumLength: 1 |
| 130 | +Pattern: ^[a-zA-Z0-9 ]+$ |
| 131 | +``` |
| 132 | + |
| 133 | +### Adapted instance type |
| 134 | + |
| 135 | +The `type` property identifies the adapted instance's WMI class resource. The value for this property |
| 136 | +must be the valid fully qualified type name for the resource. |
| 137 | + |
| 138 | +This adapter uses the following syntax for determining the fully qualified type name of a WMI class: |
| 139 | + |
| 140 | +```Syntax |
| 141 | +<namespace name>/<class name> |
| 142 | +``` |
| 143 | + |
| 144 | +For example, if a WMI class named `Win32_OperatingSystem`, the fully qualified type name for that |
| 145 | +resource is `root.cimv2/Win32_OperatingSystem`. |
| 146 | + |
| 147 | +For more information about type names in DSC, see |
| 148 | +[DSC Resource fully qualified type name schema reference][03]. |
| 149 | + |
| 150 | +```yaml |
| 151 | +Type: string |
| 152 | +Required: true |
| 153 | +Pattern: ^\w+(\.\w+){0,2}\/\w+$ |
| 154 | +``` |
| 155 | + |
| 156 | +### Adapted instance properties |
| 157 | + |
| 158 | +The `properties` of an adapted resource instance define its desired state. The value of this |
| 159 | +property must be an object. In case of the WMI adapter resource, properties are added at runtime |
| 160 | +when the adapter tries to execute. |
| 161 | + |
| 162 | +Each name for each property returns the filtered state. The property name isn't case sensitive. |
| 163 | + |
| 164 | +[!NOTE] |
| 165 | +> The current WMI adapter doesn't warn or raise an error when an invalid property is passed. |
| 166 | + |
| 167 | + |
| 168 | +```yaml |
| 169 | +Type: object |
| 170 | +Required: true |
| 171 | +``` |
| 172 | + |
| 173 | +## Exit codes |
| 174 | + |
| 175 | +The resource returns the following exit codes from operations: |
| 176 | + |
| 177 | +- [0](#exit-code-0) - Success |
| 178 | +- [1](#exit-code-1) - Error |
| 179 | + |
| 180 | +### Exit code 0 |
| 181 | + |
| 182 | +Indicates the resource operation completed without errors. |
| 183 | + |
| 184 | +### Exit code 1 |
| 185 | + |
| 186 | +Indicates the resource operation failed because the WMI query could not be executed successfully. |
| 187 | +When the resource returns this exit code, it also emits an error message with details about the failure. |
| 188 | + |
| 189 | +<!-- Link definitions --> |
| 190 | +[01]: ./examples/query-operating-system-info.md |
| 191 | +[02]: ./examples/query-filtered-disk-info.md |
| 192 | +[03]: ../../../../schemas/config/type.md |
0 commit comments