|
| 1 | +--- |
| 2 | +description: Microsoft.DSC.Transitional/RunCommandOnSet resource reference documentation |
| 3 | +ms.date: 06/30/2025 |
| 4 | +ms.topic: reference |
| 5 | +title: Microsoft.DSC.Transitional/RunCommandOnSet |
| 6 | +--- |
| 7 | + |
| 8 | +# Microsoft.DSC.Transitional/RunCommandOnSet |
| 9 | + |
| 10 | +## Synopsis |
| 11 | + |
| 12 | +Execute a command during DSC set operations. |
| 13 | + |
| 14 | +## Metadata |
| 15 | + |
| 16 | +```yaml |
| 17 | +Version : 0.1.0 |
| 18 | +Kind : resource |
| 19 | +Tags : [transitional, windows, linux, macos] |
| 20 | +Author : Microsoft |
| 21 | +``` |
| 22 | +
|
| 23 | +## Instance definition syntax |
| 24 | +
|
| 25 | +```yaml |
| 26 | +resources: |
| 27 | + - name: <instance name> |
| 28 | + type: Microsoft.DSC.Transitional/RunCommandOnSet |
| 29 | + properties: |
| 30 | + # Required properties |
| 31 | + executable: string |
| 32 | + # Optional properties |
| 33 | + arguments: array |
| 34 | + exitCode: integer |
| 35 | +``` |
| 36 | +
|
| 37 | +## Description |
| 38 | +
|
| 39 | +The `Microsoft.DSC.Transitional/RunCommandOnSet` resource enables you to run a specified executable command during the DSC |
| 40 | +set operation. This is useful for commands that need to run as part of your configuration, but haven't fully transitioned to |
| 41 | +a DSC resource. |
| 42 | + |
| 43 | +The resource allows you to: |
| 44 | + |
| 45 | +- Specify an executable to run |
| 46 | +- Pass arguments to the executable |
| 47 | +- Define a custom exit code to indicate success |
| 48 | + |
| 49 | +## Capabilities |
| 50 | + |
| 51 | +The resource has the following capabilities: |
| 52 | + |
| 53 | +- `get` - You can use the resource to retrieve the actual state of an instance. |
| 54 | +- `set` - You can use the resource to enforce the desired state for an instance. |
| 55 | + |
| 56 | +This resource uses the synthetic test functionality of DSC to determine whether an instance is in |
| 57 | +the desired state. For more information about resource capabilities, see |
| 58 | +[DSC resource capabilities][00]. |
| 59 | + |
| 60 | +## Examples |
| 61 | + |
| 62 | +1. [Run a simple command][01] - Shows how to create and delete registry keys with the |
| 63 | + `dsc resource` commands. |
| 64 | +1. [Run a PowerShell command][02] - Shows how to create, modify, and delete registry values with the |
| 65 | + `dsc resource` commands. |
| 66 | + |
| 67 | +## Properties |
| 68 | + |
| 69 | +The following list describes the properties for the resource. |
| 70 | + |
| 71 | +- **Required properties:** <a id="required-properties"></a> The following properties are always |
| 72 | + required when defining an instance of the resource. An instance that doesn't define each of these |
| 73 | + properties is invalid. |
| 74 | + |
| 75 | + - [executable](#executable) - The executable to run on set. |
| 76 | + |
| 77 | +- **Instance properties:** <a id="instance-properties"></a> The following properties are optional. |
| 78 | + They define the desired state for an instance of the resource. |
| 79 | + |
| 80 | + - [arguments](#arguments) - The argument(s), if any, to pass to the executable that runs on get or set. |
| 81 | + - [exitCode](#exitcode) - The expected exit code to indicate success, if non-zero. Default is zero for success. |
| 82 | + |
| 83 | +### executable |
| 84 | + |
| 85 | +<details><summary>Expand for <code>executable</code> property metadata</summary> |
| 86 | + |
| 87 | +```yaml |
| 88 | +Type : string |
| 89 | +IsRequired : true |
| 90 | +IsKey : false |
| 91 | +IsReadOnly : false |
| 92 | +IsWriteOnly : false |
| 93 | +``` |
| 94 | + |
| 95 | +</details> |
| 96 | + |
| 97 | +Defines the executable program or command to run during the DSC Set operation. |
| 98 | +This can be any valid executable file or command accessible from the system PATH. |
| 99 | + |
| 100 | +### arguments |
| 101 | + |
| 102 | +<details><summary>Expand for <code>arguments</code> property metadata</summary> |
| 103 | + |
| 104 | +```yaml |
| 105 | +Type : array |
| 106 | +ItemsType : string |
| 107 | +IsRequired : false |
| 108 | +IsKey : false |
| 109 | +IsReadOnly : false |
| 110 | +IsWriteOnly : false |
| 111 | +``` |
| 112 | + |
| 113 | +</details> |
| 114 | + |
| 115 | +Defines the arguments to pass to the executable. Each element in the array represents a |
| 116 | +separate argument that will be passed to the executable. |
| 117 | + |
| 118 | +### exitCode |
| 119 | + |
| 120 | +<details><summary>Expand for <code>exitCode</code> property metadata</summary> |
| 121 | + |
| 122 | +```yaml |
| 123 | +Type : integer |
| 124 | +IsRequired : false |
| 125 | +IsKey : false |
| 126 | +IsReadOnly : false |
| 127 | +IsWriteOnly : false |
| 128 | +DefaultValue : 0 |
| 129 | +``` |
| 130 | + |
| 131 | +</details> |
| 132 | + |
| 133 | +Defines the expected exit code to indicate success if not zero. By default, an exit code of 0 indicates |
| 134 | +successful execution. If your executable returns a different exit code to indicate success, specify that value here. |
| 135 | + |
| 136 | +## Instance validating schema |
| 137 | + |
| 138 | +The following snippet contains the JSON Schema that validates an instance of the resource. |
| 139 | + |
| 140 | +```json |
| 141 | +{ |
| 142 | + "type": "object", |
| 143 | + "required": [ |
| 144 | + "executable" |
| 145 | + ], |
| 146 | + "properties": { |
| 147 | + "arguments": { |
| 148 | + "title": "The argument(s), if any, to pass to the executable that runs on set", |
| 149 | + "type": "array" |
| 150 | + }, |
| 151 | + "executable": { |
| 152 | + "title": "The executable to run on set", |
| 153 | + "type": "string" |
| 154 | + }, |
| 155 | + "exitCode": { |
| 156 | + "title": "The expected exit code to indicate success, if non-zero. Default is zero for success.", |
| 157 | + "type": "integer" |
| 158 | + } |
| 159 | + }, |
| 160 | + "additionalProperties": false |
| 161 | +} |
| 162 | +``` |
| 163 | + |
| 164 | +## See also |
| 165 | + |
| 166 | +- [Microsoft.DSC.PowerShell](../../PowerShell/index.md) |
| 167 | +- [Microsoft.Windows.WindowsPowerShell](../../../../Microsoft/Windows/WindowsPowerShell/index.md) |
| 168 | + |
| 169 | +[00]: ../../../../concepts/dsc/resource-capabilities.md |
| 170 | +[01]: ./examples/run-a-simple-command.md |
| 171 | +[02]: ./examples/run-powershell-command.md |
0 commit comments