I am having a hard time piping a file to Get-Content (version PS 5.1).
Module code:
[Cmdlet(VerbsDiagnostic.Test, "FilePiping")]
public class PSTestFilePiping : PSCmdlet
{
[Parameter(Position = 0, Mandatory = true)]
public string FileName { get; set; }
protected override void ProcessRecord()
{
WriteObject(new System.IO.FileInfo(FileName));
}
}
Commands:
$x = Test-FilePiping .\readme.txt
$y = gci .\readme.txt
(I am using a relative path for simplicity)
Both $x and $y are a FileInfo object according to GetType():
IsPublic IsSerial Name BaseType
True True FileInfo System.IO.FileSystemInfo
Yet I cannot do:
$x | gc
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
but I can do:
$y | gc
This has me flummoxed.
Where did I go wrong?