I have come up with a workable solution. First, define your pipeline input parameter in your cmdlet to take an array rather than just a single object. In my case I am using an array of strings:
[CmdletBinding()]
param(
[parameter(ValueFromPipeline=$true)]
[string[]]$InputObject
)
(Side note: $InputObject is the customary name for pipelined input. Don't use $Input because that is an automatic variable.)
In the Process section of the script, add a foreach loop to operate on the array:
Process
{
foreach ($object in $InputObject) {
# Do stuff with $object
}
}
To run the script in the vscode debugger, you can specify the arguments in your launch configuration (in launch.json) something like this:
"args": ["-InputObject (Get-Content /path/to/myFile.txt)"]
For reference, this is what my launch configuration looks like:
{
"name": "PowerShell Launch Select-Blah.ps1",
"type": "PowerShell",
"request": "launch",
"script": "${workspaceFolder}/Select-Blah.ps1",
"cwd": "${cwd}",
"args": ["-InputObject (Get-Content /path/to/myFile.txt)"]
}
You can select "PowerShell Launch Select-Blah.ps1" in the dropdown in the debugger, and hit f5 to launch it.
Edit, another possibility:
If you want to have a singular $InputObject:
[CmdletBinding()]
param(
[parameter(ValueFromPipeline=$true)]
[string]$InputObject
)
You can use the -Raw switch with Get-Content to get a single string:
"args": ["-InputObject (Get-Content -Raw /path/to/myFile.txt)"]