Skip to content

Commit cc6260e

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
fix winps manifest, start of support for input
1 parent 91bc422 commit cc6260e

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

resources/PSScript/psscript.dsc.resource.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
"testScript": {
6767
"type": ["string", "null"]
6868
},
69+
"input": {
70+
"type": ["string", "boolean", "integer", "object", "array", "null"]
71+
},
6972
"output": {
7073
"type": ["object", "null"]
7174
},

resources/PSScript/psscript.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ $ps = [PowerShell]::Create().AddScript({
6161
$DebugPreference = 'Continue'
6262
$VerbosePreference = 'Continue'
6363
$ErrorActionPreference = 'Stop'
64-
}).AddScript($script)
64+
})
65+
66+
if ($null -ne $scriptObject.input) {
67+
$null = $ps.AddScript({
68+
$global:inputArg = $scriptObject.input
69+
})
70+
}
71+
72+
$null = $ps.AddScript($script)
73+
6574
$ps.Streams.Error.add_DataAdded({
6675
param($sender, $args)
6776
Write-DscTrace -Level Error -Message $sender.Message

resources/PSScript/psscript.tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,19 @@ Describe 'Tests for PSScript resource' {
264264
$result.results[0].result.actualState.output[0].PSEdition | Should -BeExactly 'Core'
265265
$result.results[0].result.actualState.output[0].PSVersion.Major | Should -Be 7
266266
}
267+
268+
It 'Input can be a string for <resourceType>' -TestCases $testCases {
269+
param($resourceType)
270+
271+
$yaml = @'
272+
getScript: |
273+
"Input: $input"
274+
input: "This is a string"
275+
'@
276+
$result = dsc resource get -r $resourceType -i $yaml 2> $TestDrive/error.txt | ConvertFrom-Json
277+
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.txt -Raw | Out-String)
278+
$result.actualState.output.Count | Should -Be 1 -Because ($result | ConvertTo-Json -Depth 10 | Out-String)
279+
$result.actualState.output[0] | Should -BeExactly "Input: This is a string"
280+
}
281+
267282
}

resources/PSScript/winpsscript.dsc.resource.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Enable running Windows PowerShell 5.1 scripts inline",
55
"version": "0.1.0",
66
"get": {
7-
"executable": "pwsh",
7+
"executable": "powershell",
88
"args": [
99
"-NoLogo",
1010
"-NonInteractive",
@@ -18,7 +18,7 @@
1818
"input": "stdin"
1919
},
2020
"set": {
21-
"executable": "pwsh",
21+
"executable": "powershell",
2222
"args": [
2323
"-NoLogo",
2424
"-NonInteractive",
@@ -34,7 +34,7 @@
3434
"return": "state"
3535
},
3636
"test": {
37-
"executable": "pwsh",
37+
"executable": "powershell",
3838
"args": [
3939
"-NoLogo",
4040
"-NonInteractive",
@@ -66,6 +66,9 @@
6666
"testScript": {
6767
"type": ["string", "null"]
6868
},
69+
"input": {
70+
"type": ["string", "boolean", "integer", "object", "array", "null"]
71+
},
6972
"output": {
7073
"type": ["object", "null"]
7174
},

0 commit comments

Comments
 (0)