|
1 |
| ---- |
2 |
| -description: Microsoft.Windows/WindowsPowerShell resource adapter reference documentation |
3 |
| -ms.date: 03/25/2025 |
4 |
| -ms.topic: reference |
5 |
| -title: Microsoft.Windows/WindowsPowerShell |
6 |
| ---- |
7 |
| - |
8 |
| -# Microsoft.Windows/WindowsPowerShell |
9 |
| - |
10 |
| -## Synopsis |
11 |
| - |
12 |
| -Manage PowerShell DSC resources. This adapter enables you to use class-based, script-based, or binary PowerShell DSC resources available on the system. |
13 |
| - |
14 |
| -## Metadata |
15 |
| - |
16 |
| -```yaml |
17 |
| -Version : 0.1.0 |
18 |
| -Kind : resource |
19 |
| -Tags : [Windows] |
20 |
| -Author : Microsoft |
21 |
| -``` |
22 |
| -
|
23 |
| -## Instance definition syntax |
24 |
| -
|
25 |
| -```yaml |
26 |
| -resources: |
27 |
| - - name: <instanceName> |
28 |
| - type: Microsoft.Windows/WindowsPowerShell |
29 |
| - properties: |
30 |
| - resources: |
31 |
| - - name: <instanceName> |
32 |
| - type: <moduleName>/<resourceName> |
33 |
| - properties: |
34 |
| - # Instance properties |
35 |
| - Ensure: Present |
36 |
| - |
37 |
| -# Or from v3.1.0-preview.2 onwards |
38 |
| -resources: |
39 |
| -- name: <instanceName> |
40 |
| - type: <moduleName>/<resourceName> |
41 |
| - properties: |
42 |
| - # Instance properties |
43 |
| - Ensure: Present |
44 |
| -``` |
45 |
| -
|
46 |
| -## Description |
47 |
| -
|
48 |
| -The `Microsoft.Windows/WindowsPowerShell` resource adapter enables you to invoke PSDSC resources. The resource can: |
49 |
| - |
50 |
| -- Execute script-based DSC resources |
51 |
| -- Run class-based DSC resource methods |
52 |
| -- Execute binary DSC resources |
53 |
| - |
54 |
| -> [!NOTE] |
55 |
| -> This resource is installed with DSC itself on Windows systems. |
56 |
| -> |
57 |
| -> You can update this resource by updating DSC. When you update DSC, the updated version of this |
58 |
| -> resource is automatically available. |
59 |
| - |
60 |
| -## Requirements |
61 |
| - |
62 |
| -- The resource is only usable on a Windows system. |
63 |
| -- The resource must run in a process context that has appropriate permissions for the DSC resource to be executed. |
64 |
| -- The PowerShell modules exposing DSC resources should be installed in |
65 |
| - `%PROGRAMFILES%\WindowsPowerShell\Modules` or |
66 |
| - `%SystemRoot%\System32\WindowsPowerShell\v1.0\Modules` |
67 |
| - |
68 |
| -## Capabilities |
69 |
| - |
70 |
| -The resource adapter has the following capabilities: |
71 |
| - |
72 |
| -- `get` - You can use the resource to retrieve the actual state of a DSC resource instance. |
73 |
| -- `set` - You can use the resource to enforce the desired state for a DSC resource instance. |
74 |
| -- `test` - You can use the resource to determine whether a DSC resource instance is in the desired state. |
75 |
| -- `export` - You can use the resource to discover and enumerate DSC resource instances currently installed and available on the system. |
76 |
| -- `list` - Lists available PowerShell DSC resources on your system that can be used with `dsc.exe`. |
77 |
| - |
78 |
| -> [!NOTE] |
79 |
| -> The `export` capability is only available with class-based DSC resources. |
80 |
| -> Script-based and binary DSC resources do not support the export operation. |
81 |
| - |
82 |
| -## Examples |
83 |
| - |
84 |
| -1. [Manage a Windows Service][01] - Shows how to manage a Windows service |
85 |
| - |
86 |
| -## Properties |
87 |
| - |
88 |
| -Unlike standard resources, the `Microsoft.Windows/WindowsPowerShell` resource adapter doesn't have directly exposed properties |
89 |
| -in its schema because it acts as a bridge to PowerShell DSC resource. Instead, the adapter: |
90 |
| - |
91 |
| -1. Dynamically discovers the property schema for each PowerShell DSC resource |
92 |
| -2. Stores the schema properties in a cache file for improved performance in subsequent operations |
93 |
| -3. Passes properties to the underlying PowerShell DSC resource |
94 |
| - |
95 |
| -The adapter maintains a cache of resource schemas at: |
96 |
| - |
97 |
| -- Windows: `%LOCALAPPDATA%\dsc\WindowsPSAdapterCache.json` |
98 |
| - |
99 |
| -To list the schema properties for a PowerShell DSC resource, you can run the following command: |
100 |
| - |
101 |
| -```powershell |
102 |
| -dsc resource list --adapter Microsoft.Windows/WindowsPowerShell <moduleName>/<resourceName> | |
103 |
| - ConvertFrom-Json | |
104 |
| - Select-Object properties |
105 |
| -``` |
106 |
| - |
107 |
| -You can also retrieve more information by directly reading it from the cache file: |
108 |
| - |
109 |
| -```powershell |
110 |
| -$cache = Get-Content -Path "$env:LOCALAPPDATA\dsc\WindowsPSAdapterCache.json" | |
111 |
| - ConvertFrom-Json |
112 |
| -
|
113 |
| -($cache.ResourceCache | Where-Object -Property type -EQ '<moduleName>/<resourceName>').DscResourceInfo.Properties |
114 |
| -``` |
115 |
| - |
116 |
| -## Exit codes |
117 |
| - |
118 |
| -The resource returns the following exit codes from operations: |
119 |
| - |
120 |
| -- [0](#exit-code-0) - Success |
121 |
| -- [1](#exit-code-1) - Error |
122 |
| - |
123 |
| -### Exit code 0 |
124 |
| - |
125 |
| -Indicates the resource operation completed without errors. |
126 |
| - |
127 |
| -### Exit code 1 |
128 |
| - |
129 |
| -Indicates the resource operation failed because the underlying DSC resource method or Invoke-DscResource call did not succeed. |
130 |
| -When the resource returns this exit code, it also emits an error message with details about the failure. |
131 |
| - |
132 |
| -<!-- Link definitions --> |
133 |
| -[01]: ./examples/manage-a-windows-service.md |
0 commit comments