I could not find an answer to this question anywhere.
How can a PowerShell script written in a file (as I understand, it cannot be a function in order to allow the pipelining directly to the script) be made to accept either pipeline input or a file input argument? The following criteria must be met:
- either of which must be mandatory;
- pipeline input is to be processed only after receiving all input into an array;
- input argument is a file and the path must be validated;
- a second optional argument specifies an output file.
The idea is to achieve a similar behavior to standard Linux commands as in cat file | <command> [-o out] or <command> -f file [-o out], in PowerShell being cat file | .\script.ps1 [-OutFile out] or .\script.ps1 -File file [-OutFile out].