We will mostly use the help documentation to demonstrate the two different kinds of pipeline input.
- At the prompt, type the following command:
PS> Get-Help Get-Item -Parameter Path
It says the parameter accepts string input, and accepts input by property name as well as by value.
- Type the following to see if a valid string is accepted.
PS> '/home/ram/random' | Get-Item
- Let us try something similar with Get-Date.
PS> Get-Help Get-Date -Parameter *
The Date parameter accepts values through the pipeline. However, the type is DateTime, and not string.
- Try sending a valid string through the pipeline to see if it gets converted into date.
PS> '21 June 2018' | Get-Date
It did convert the string into date and time.
- Now, let us go back to getting details of the current directory. This time, however, we would pick only the FullName property of the object.
PS> Get-Item . | Select-Object FullName
- Pass this through the pipeline to the Get-ChildItem cmdlet.
PS> Get-Item . | Select-Object FullName | Get-ChildItem
There is an error.
- Change the property name to LiteralPath.
PS> Get-Item . | Select-Object @{Name = 'LiteralPath'; Expression = {$_.FullName}}
- Pass the object to Get-ChildItem through the pipeline.
PS> Get-Item . | Select-Object @{Name = 'LiteralPath'; Expression = {$_.FullName}} | Get-ChildItem
That worked.