PowerShell Accepting Pipeline Input


PowerShell Accepting Pipeline Input. There are two ways to accept pipeline input

  1. ValueFromPipeline = $true
  2. ValueFromPipelineByPropertyName = $true

Prerequisite

[cmdletbinding()]
Param
(
[Parameter(ValueFromPipeline)]] OR [Parameter(ValueFromPipelineByPropertyName)]]
)

ValueFromPipeline

This method accepts the whole object as input and gives you access to all of the objects properties.

ValueFromPipelineByPropertyName

This method accepts only the value of a single property.
Equivalent of $Object | Select-Object -ExpandProperty Name

  • https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.1