Accepting input from file

This process is significantly different in PowerShell, compared to Bash. In Bash, we call the command first, and then ask it to accept input from a file. In PowerShell, we make PowerShell read the contents of the input file first, and then send the output to the command that accepts input through the pipeline.

In our recipe, we read the contents of the file, input.txt, which contained a list of four file names. We used Get-Content to read the content from the file. Get-Content sent the output to the standard out at first, thereby showing us the contents of the file. We then added a pipe to tell PowerShell that we need further processing, and then, added Remove-Item to the command chain. (Remove-Item deletes items, which could be directories, files or links.)

As we would see later in this chapter, the first parameter (positional parameter, position 1) of Remove-Item is Path, which is also the parameter that accepts input through the pipeline. For more information, run the following command and read about the Path parameter of Remove-Item.

PS> Get-Help Remove-Item -Parameter Path
..................Content has been hidden....................

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