How to do it...

We will mostly use the help documentation to demonstrate the two different kinds of pipeline input.

  1. 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.

  1. Type the following to see if a valid string is accepted.
PS> '/home/ram/random' | Get-Item
  1. 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.

  1. 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.

  1. 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
  1. Pass this through the pipeline to the Get-ChildItem cmdlet.
PS> Get-Item . | Select-Object FullName | Get-ChildItem

There is an error.

  1. Change the property name to LiteralPath.
PS> Get-Item . | Select-Object @{Name = 'LiteralPath'; Expression = {$_.FullName}}
  1. Pass the object to Get-ChildItem through the pipeline.
PS> Get-Item . | Select-Object @{Name = 'LiteralPath'; Expression = {$_.FullName}} | Get-ChildItem

That worked.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.66.178