0

I have the following script:

$PathToFiles = 'C:\Data_Files\Debug'
$Files = Get-ChildItem -Path $PathToFiles| Where-Object {$_.Fullname -match "[0-9]{15}\.xml"}
$Files|ForEach-Object{
  $ID = [io.path]::GetFileNameWithoutExtension($_.Name)
  $Data = [PSCustomObject] @{
    ID = $ID
    PathToFiles = $PathToFiles
  }
  Write-Output -InputObject $Data
}

I am attempting to use the pipeline as input to a different PS script.
The command line looks like .\PS1.ps1 | .\PS2.ps1 The PS2.ps1 script correctly processes the input object if I simply feed a single object through the pipeline to it. If I run this script just as .\PS1.ps1 I get a long list of the object that I am outputting, but when I run it attempting to send through the pipeline, only the last object processed is passed through to the second script. How do I get all the objects processing?

dstroupe
  • 98
  • 5
  • sounds like `.\PS2.ps1` is missing a `process` block. unless you show your second file we can't help that much but guess only – Santiago Squarzon Oct 02 '22 at 15:20
  • Read about [advanced functions](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced?view=powershell-7.2) and [this](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_methods?view=powershell-7.2). – zett42 Oct 02 '22 at 15:21
  • See this answer for an example using a PowerShell script: https://stackoverflow.com/a/885627/7571258 – zett42 Oct 02 '22 at 15:26
  • Why so difficult. Get-ChildItem returns objects that have a `.BaseName` (=> filename without extension) and a `.DirectoryName` (=> the path to that file) property already.. – Theo Oct 02 '22 at 15:28

0 Answers0