@@ -14,16 +14,20 @@ execute a simple command during the **Set** operation.
14
14
15
15
## Test whether the command would run
16
16
17
- The following snippet shows how you can use the resource with the [ dsc resource test] [ 01 ] command to check whether the command would run.
17
+ The following snippet shows how you can use the resource with the [ dsc resource test] [ 00 ] command to check whether
18
+ the command would run.
18
19
19
20
> [ !NOTE]
20
21
> The ` dsc resource test ` command performs a synthetic test on this resource. ` Microsoft.DSC.Transitional/RunCommandOnSet ` doesn't have
21
- > the ` test ` capability defined in the [ resource manifest] [ 02 ]
22
+ > the ` test ` capability defined in the [ resource manifest] [ 01 ]
22
23
23
24
``` powershell
24
25
$instance = @{
25
- executable = "echo"
26
- arguments = @("Configuration applied successfully")
26
+ executable = "C:\Windows\system32\cmd.exe"
27
+ arguments = @(
28
+ '/C',
29
+ 'echo Hello world'
30
+ )
27
31
} | ConvertTo-Json
28
32
29
33
dsc resource test --resource Microsoft.DSC.Transitional/RunCommandOnSet --input $instance
@@ -34,30 +38,26 @@ When testing the resource, DSC returns a result indicating the desired state:
34
38
``` yaml
35
39
desiredState :
36
40
arguments :
37
- - Configuration applied successfully
38
- executable : echo
41
+ - /C
42
+ - echo Hello world
43
+ executable : C:\Windows\system32\cmd.exe
39
44
actualState :
40
- executable : echo
45
+ executable : C:\Windows\system32\cmd.exe
41
46
arguments :
42
- - Configuration applied successfully
47
+ - /C
48
+ - echo Hello world
43
49
inDesiredState : true
44
50
differingProperties : []
45
51
` ` `
46
52
47
- The ` inDesiredState` field of the result object is set to `true`, indicating that the command would be executed during a **Set** operation.
53
+ The ` inDesiredState` field always returns `true` because of [pretest][02] is supported.
54
+ This means the command is always executed during the **Set** operation.
48
55
49
56
# # Run the command
50
57
51
58
To execute the command, use the [dsc resource set][03] command.
52
59
53
60
` ` ` powershell
54
- $instance = @{
55
- executable = "C:\W indows\s ystem32\c md.exe"
56
- arguments = @(
57
- '/C',
58
- 'echo Hello world'
59
- )
60
- } | ConvertTo-Json
61
61
dsc resource set --resource Microsoft.DSC.Transitional/RunCommandOnSet --input $instance
62
62
` ` `
63
63
@@ -84,6 +84,7 @@ changedProperties: []
84
84
> If you want to capture the output, you should redirect it to a file.
85
85
86
86
<!-- Link reference definitions -->
87
- [01] : ../../../../../cli/resource/test.md
88
- [02] : ../../../../../../schemas/resource/manifest/test.md
87
+ [00] : ../../../../../cli/resource/test.md
88
+ [01] : ../../../../../../schemas/resource/manifest/test.md
89
+ [02] : ../../../../../../../reference/cli/resource/set.md
89
90
[03] : ../../../../../cli/resource/set.md
0 commit comments