1

I have got a robust script which gets, parse and uses some data from .csv file. To run the script I can use

.\script.ps1 -d data_file.csv

The thing is I cannot interfere into script itself that is why i need to create some kind of a wrapper which will create new csv file and use script.ps1 with a new made file. I am wondering if there is a possibility to create a csv file as an object which will be passed directly to the command like this

.\script.ps1 -d csv_file_as_object.csv

without creating file in some path directory.

mil.troj
  • 13
  • 3

1 Answers1

1

What you'd need in this case is the equivalent of Bash's process substitution (<(...)), which, in a nutshell, would allow you to present a command's output as the content of a temporary file whose path is output:

.\scripts.ps1 -d <(... | ConvertTo-Csv) # !! does NOT work in PowerShell

Note: ... | ConverTo-Csv stands for whatever command is needed to transform the original CSV in-memory.

No such feature exists in PowerShell as of Windows PowerShell v5.1 / PowerShell Core v6.1, but it has been proposed.

If .\scripts.ps1 happens to also accept stdin input (via pseudo-path - indicating stdin input), you could try:

 ... | ConvertTo-Csv | .\script.ps1 -d -

Otherwise, your only option is to:

  • save your modified CSV data to a temporary file
  • pass that temporary file's path to .\script.ps1
  • remove the temporary file.
mklement0
  • 382,024
  • 64
  • 607
  • 775