DSC icon indicating copy to clipboard operation
DSC copied to clipboard

Replace -Command with -File for PowerShell resource invocations

Open Copilot opened this issue 1 month ago • 2 comments

All PowerShell and pwsh invocations using -Command to execute script files now use -File instead. Scripts modified to read JSON input from stdin using the $input automatic variable while retaining the ValueFromPipeline parameter attribute.

Changes

Resource manifests (7 files)

Changed invocation pattern from:

"args": ["-Command", "$input | ./script.ps1", "operation"]

to:

"args": ["-File", "./script.ps1", "operation"]

Files:

  • resources/reboot_pending/reboot_pending.dsc.resource.json
  • resources/PSScript/{psscript,winpsscript}.dsc.resource.json
  • adapters/wmi/wmi.dsc.resource.json
  • adapters/powershell/{powershell,windowspowershell}.dsc.resource.json
  • adapters/powershell/Tests/TestAdapter/testadapter.dsc.resource.json

PowerShell scripts (4 files)

Scripts now read from stdin using the $input automatic variable while keeping the ValueFromPipeline parameter attribute:

param(
    [Parameter(Position = 0)]
    [string]$Operation,
    [Parameter(ValueFromPipeline = $true)]
    [string]$jsonInput = '@{}'
)

# Read from stdin using $input automatic variable
$stdinData = $input | Out-String
if (-not [string]::IsNullOrWhiteSpace($stdinData)) {
    $jsonInput = $stdinData
}

Files:

  • resources/PSScript/psscript.ps1
  • adapters/wmi/wmi.resource.ps1
  • adapters/powershell/psDscAdapter/powershell.resource.ps1
  • adapters/powershell/Tests/TestAdapter/testadapter.resource.ps1
Original prompt

update all the dsc.resource.json files which have executable as pwsh or powershell and use -c or -command parameter for invocation with -file. When that change is done, we also need to update the script that is invoked and use $input to receive the parameters in the script


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Nov 20 '25 18:11 Copilot

@copilot instead of using [System.Console]::In.ReadToEnd() use the $input automatic variable from PowerShell. keep the parameter which has the ValueFromPipeline attribute

adityapatwardhan avatar Nov 20 '25 18:11 adityapatwardhan

@copilot instead of using [System.Console]::In.ReadToEnd() use the $input automatic variable from PowerShell. keep the parameter which has the ValueFromPipeline attribute

Updated in commit c5d9d2b. All PowerShell scripts now use $input | Out-String to read from stdin while keeping the ValueFromPipeline parameter attribute.

PSScript tests: 21/21 passing ✅

Note: Some PowerShell adapter tests are showing "Empty input provided" errors (10/20 passing). Investigating whether this is related to the changes.

Copilot avatar Nov 20 '25 19:11 Copilot