Skip to content

Commit 4c6b634

Browse files
committed
fix handling of input and add example
1 parent 206bc32 commit 4c6b634

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

dsc/examples/psscript.dsc.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
# Example configuration mixing native app resources with classic PS resources
22
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
3+
parameters:
4+
myName:
5+
type: string
6+
defaultValue: Steve
7+
myObject:
8+
type: object
9+
defaultValue:
10+
color: green
11+
number: 10
312
resources:
413
- name: Use PS script
514
type: Microsoft.DSC.Transitional/PowerShellScript
615
properties:
16+
input:
17+
- name: "[parameters('myName')]"
18+
- object: "[parameters('myObject')]"
719
getScript: |
20+
param($inputArray)
21+
822
Write-Warning "This is a warning message"
923
# any output will be collected and returned
10-
$PSVersionTable
24+
"My name is " + $inputArray[0].name
25+
"My color is " + $inputArray[1].object.color

resources/PSScript/psscript.dsc.resource.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"type": ["string", "boolean", "integer", "object", "array", "null"]
7272
},
7373
"output": {
74-
"type": ["object", "null"]
74+
"type": ["array", "null"]
7575
},
7676
"_inDesiredState": {
7777
"type": ["boolean", "null"],

resources/PSScript/psscript.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ Describe 'Tests for PSScript resource' {
260260
$configPath = Join-Path $PSScriptRoot '../../dsc/examples/psscript.dsc.yaml'
261261
$result = dsc config get -f $configPath 2> $TestDrive/error.txt | ConvertFrom-Json -Depth 10
262262
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.txt -Raw | Out-String)
263-
$result.results[0].result.actualState.output.Count | Should -Be 1 -Because ($result | ConvertTo-Json -Depth 10 | Out-String)
264-
$result.results[0].result.actualState.output[0].PSEdition | Should -BeExactly 'Core'
265-
$result.results[0].result.actualState.output[0].PSVersion.Major | Should -Be 7
263+
$result.results[0].result.actualState.output.Count | Should -Be 2 -Because ($result | ConvertTo-Json -Depth 10 | Out-String)
264+
$result.results[0].result.actualState.output[0] | Should -BeExactly 'My name is Steve'
265+
$result.results[0].result.actualState.output[1] | Should -BeExactly 'My color is green'
266266
}
267267

268268
It 'Input can be a string for <resourceType>' -TestCases $testCases {

resources/PSScript/winpsscript.dsc.resource.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"exitCodes": {
5252
"0": "Success",
5353
"1": "PowerShell script execution failed",
54-
"2": "PowerShell exception occurred"
54+
"2": "PowerShell exception occurred",
55+
"3": "Script had errors"
5556
},
5657
"schema": {
5758
"embedded": {
@@ -70,7 +71,7 @@
7071
"type": ["string", "boolean", "integer", "object", "array", "null"]
7172
},
7273
"output": {
73-
"type": ["object", "null"]
74+
"type": ["array", "null"]
7475
},
7576
"_inDesiredState": {
7677
"type": ["boolean", "null"],

0 commit comments

Comments
 (0)