diff --git a/adapters/powershell/Tests/TestAdapter/testadapter.dsc.resource.json b/adapters/powershell/Tests/TestAdapter/testadapter.dsc.resource.json index e05c85061..a3995edbe 100644 --- a/adapters/powershell/Tests/TestAdapter/testadapter.dsc.resource.json +++ b/adapters/powershell/Tests/TestAdapter/testadapter.dsc.resource.json @@ -14,8 +14,9 @@ "-NoLogo", "-NonInteractive", "-NoProfile", - "-Command", - "./testadapter.resource.ps1 List" + "-File", + "./testadapter.resource.ps1", + "List" ] }, "config": "full" @@ -26,8 +27,9 @@ "-NoLogo", "-NonInteractive", "-NoProfile", - "-Command", - "$Input | ./testadapter.resource.ps1 Get" + "-File", + "./testadapter.resource.ps1", + "Get" ], "input": "stdin" }, @@ -37,8 +39,9 @@ "-NoLogo", "-NonInteractive", "-NoProfile", - "-Command", - "$Input | ./testadapter.resource.ps1 Set" + "-File", + "./testadapter.resource.ps1", + "Set" ], "input": "stdin", "implementsPretest": true @@ -49,8 +52,9 @@ "-NoLogo", "-NonInteractive", "-NoProfile", - "-Command", - "$Input | ./testadapter.resource.ps1 Test" + "-File", + "./testadapter.resource.ps1", + "Test" ], "input": "stdin" }, @@ -60,8 +64,9 @@ "-NoLogo", "-NonInteractive", "-NoProfile", - "-Command", - "$Input | ./testadapter.resource.ps1 Export" + "-File", + "./testadapter.resource.ps1", + "Export" ], "input": "stdin" }, @@ -71,8 +76,9 @@ "-NoLogo", "-NonInteractive", "-NoProfile", - "-Command", - "$Input | ./testadapter.resource.ps1 Validate" + "-File", + "./testadapter.resource.ps1", + "Validate" ], "input": "stdin" }, diff --git a/adapters/powershell/Tests/TestAdapter/testadapter.resource.ps1 b/adapters/powershell/Tests/TestAdapter/testadapter.resource.ps1 index 4dae5e0ac..440911788 100644 --- a/adapters/powershell/Tests/TestAdapter/testadapter.resource.ps1 +++ b/adapters/powershell/Tests/TestAdapter/testadapter.resource.ps1 @@ -9,6 +9,14 @@ param( [string]$jsonInput = '@{}' ) +# Read JSON input from stdin using $input automatic variable for operations that need it +if ($Operation -ne 'List') { + $stdinData = $input | Out-String + if (-not [string]::IsNullOrWhiteSpace($stdinData)) { + $jsonInput = $stdinData + } +} + function Write-DscTrace { param( [Parameter(Mandatory = $false)] diff --git a/adapters/powershell/powershell.dsc.resource.json b/adapters/powershell/powershell.dsc.resource.json index e481b0737..25fced4ed 100644 --- a/adapters/powershell/powershell.dsc.resource.json +++ b/adapters/powershell/powershell.dsc.resource.json @@ -16,8 +16,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "./psDscAdapter/powershell.resource.ps1 List" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "List" ] }, "config": "full" @@ -30,8 +31,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./psDscAdapter/powershell.resource.ps1 Get" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "Get" ], "input": "stdin" }, @@ -43,8 +45,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./psDscAdapter/powershell.resource.ps1 Set" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "Set" ], "input": "stdin", "implementsPretest": true @@ -57,8 +60,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./psDscAdapter/powershell.resource.ps1 Test" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "Test" ], "input": "stdin", "return": "state" @@ -71,8 +75,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./psDscAdapter/powershell.resource.ps1 Export" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "Export" ], "input": "stdin", "return": "state" @@ -85,8 +90,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./psDscAdapter/powershell.resource.ps1 Validate" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "Validate" ], "input": "stdin" }, diff --git a/adapters/powershell/psDscAdapter/powershell.resource.ps1 b/adapters/powershell/psDscAdapter/powershell.resource.ps1 index fd4d116d6..f34827394 100644 --- a/adapters/powershell/psDscAdapter/powershell.resource.ps1 +++ b/adapters/powershell/psDscAdapter/powershell.resource.ps1 @@ -9,6 +9,14 @@ param( [string]$jsonInput = '@{}' ) +# Read JSON input from stdin using $input automatic variable for operations that need it +if ($Operation -ne 'List' -and $Operation -ne 'ClearCache') { + $stdinData = $input | Out-String + if (-not [string]::IsNullOrWhiteSpace($stdinData)) { + $jsonInput = $stdinData + } +} + function Write-DscTrace { param( [Parameter(Mandatory = $false)] diff --git a/adapters/powershell/windowspowershell.dsc.resource.json b/adapters/powershell/windowspowershell.dsc.resource.json index 297b44d05..751786b37 100644 --- a/adapters/powershell/windowspowershell.dsc.resource.json +++ b/adapters/powershell/windowspowershell.dsc.resource.json @@ -16,8 +16,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "./psDscAdapter/powershell.resource.ps1 List" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "List" ] }, "config": "full" @@ -30,8 +31,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./psDscAdapter/powershell.resource.ps1 Get" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "Get" ], "input": "stdin" }, @@ -43,8 +45,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./psDscAdapter/powershell.resource.ps1 Set" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "Set" ], "input": "stdin", "preTest": true @@ -57,8 +60,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./psDscAdapter/powershell.resource.ps1 Test" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "Test" ], "input": "stdin", "return": "state" @@ -71,8 +75,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./psDscAdapter/powershell.resource.ps1 Export" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "Export" ], "input": "stdin", "return": "state" @@ -85,8 +90,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./psDscAdapter/powershell.resource.ps1 Validate" + "-File", + "./psDscAdapter/powershell.resource.ps1", + "Validate" ] }, "exitCodes": { diff --git a/adapters/wmi/wmi.dsc.resource.json b/adapters/wmi/wmi.dsc.resource.json index d37ca2dd8..b6536b709 100644 --- a/adapters/wmi/wmi.dsc.resource.json +++ b/adapters/wmi/wmi.dsc.resource.json @@ -16,8 +16,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "./wmi.resource.ps1 List" + "-File", + "./wmi.resource.ps1", + "List" ] }, "config": "full" @@ -30,8 +31,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./wmi.resource.ps1 Get" + "-File", + "./wmi.resource.ps1", + "Get" ], "input": "stdin" }, @@ -43,8 +45,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./wmi.resource.ps1 Set" + "-File", + "./wmi.resource.ps1", + "Set" ], "input": "stdin", "implementsPretest": false @@ -57,8 +60,9 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$Input | ./wmi.resource.ps1 Validate" + "-File", + "./wmi.resource.ps1", + "Validate" ] }, "exitCodes": { diff --git a/adapters/wmi/wmi.resource.ps1 b/adapters/wmi/wmi.resource.ps1 index 102db4d34..27a7001c4 100644 --- a/adapters/wmi/wmi.resource.ps1 +++ b/adapters/wmi/wmi.resource.ps1 @@ -9,6 +9,14 @@ param( [string]$jsonInput = '@{}' ) +# Read JSON input from stdin using $input automatic variable for operations that need it +if ($Operation -ne 'List') { + $stdinData = $input | Out-String + if (-not [string]::IsNullOrWhiteSpace($stdinData)) { + $jsonInput = $stdinData + } +} + # Import private functions $wmiAdapter = Import-Module "$PSScriptRoot\wmiAdapter.psm1" -Force -PassThru diff --git a/resources/PSScript/psscript.dsc.resource.json b/resources/PSScript/psscript.dsc.resource.json index fda07988d..b754c7853 100644 --- a/resources/PSScript/psscript.dsc.resource.json +++ b/resources/PSScript/psscript.dsc.resource.json @@ -11,8 +11,8 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$input | ./psscript.ps1", + "-File", + "./psscript.ps1", "get" ], "input": "stdin" @@ -25,8 +25,8 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$input | ./psscript.ps1", + "-File", + "./psscript.ps1", "set" ], "implementsPretest": true, @@ -41,8 +41,8 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$input | ./psscript.ps1", + "-File", + "./psscript.ps1", "test" ], "input": "stdin", diff --git a/resources/PSScript/psscript.ps1 b/resources/PSScript/psscript.ps1 index 2b395dce1..230e37fd4 100644 --- a/resources/PSScript/psscript.ps1 +++ b/resources/PSScript/psscript.ps1 @@ -5,10 +5,16 @@ param( [Parameter(Mandatory = $true, Position = 0)] [ValidateSet('Get', 'Set', 'Test')] [string]$Operation, - [Parameter(Mandatory = $true, Position = 1, ValueFromPipeline = $true)] - [string]$jsonInput + [Parameter(Mandatory = $false, Position = 1, ValueFromPipeline = $true)] + [string]$jsonInput = '' ) +# Read JSON input from stdin using $input automatic variable +$stdinData = $input | Out-String +if (-not [string]::IsNullOrWhiteSpace($stdinData)) { + $jsonInput = $stdinData +} + function Write-DscTrace { param( [Parameter(Mandatory = $true)] diff --git a/resources/PSScript/winpsscript.dsc.resource.json b/resources/PSScript/winpsscript.dsc.resource.json index 25b73b81c..e45fa5568 100644 --- a/resources/PSScript/winpsscript.dsc.resource.json +++ b/resources/PSScript/winpsscript.dsc.resource.json @@ -11,8 +11,8 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$input | ./psscript.ps1", + "-File", + "./psscript.ps1", "get" ], "input": "stdin" @@ -25,8 +25,8 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$input | ./psscript.ps1", + "-File", + "./psscript.ps1", "set" ], "implementsPretest": true, @@ -41,8 +41,8 @@ "-NoProfile", "-ExecutionPolicy", "Bypass", - "-Command", - "$input | ./psscript.ps1", + "-File", + "./psscript.ps1", "test" ], "input": "stdin", diff --git a/resources/reboot_pending/reboot_pending.dsc.resource.json b/resources/reboot_pending/reboot_pending.dsc.resource.json index 590d9dc95..5f6606a40 100644 --- a/resources/reboot_pending/reboot_pending.dsc.resource.json +++ b/resources/reboot_pending/reboot_pending.dsc.resource.json @@ -9,7 +9,7 @@ "-NoLogo", "-NonInteractive", "-NoProfile", - "-Command", + "-File", "reboot_pending.resource.ps1" ] },