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