Declare get accessors in PowerShell cmdlet options

According to MSDN :

"Parameters must be declared in public non-static fields or properties. Parameters must be declared by properties. The property must have a public accessory, and if ValueFromPipeline or the keyword ValueFromPipelineByPropertyName is specified, the property must have public access to accessories."

Why do I need to declare get accessors in cmdlet parameters ValueFromPipeline? As far as I know, PowerShell only needs to insert its values, and not read them. Thanks (by the way, they are just curious about this behavior :)).

+5
source share
1 answer

PowerShell , ValueFromPipeline ValueFromPipelineByPropertyName, , .

:

New-Post -Title <string>
Set-Post -InputObject <Post> -Title <string>

:

  • New-Post Post , Title
  • InputObject Set-Post ValueFromPipeline = true
  • Title Set-Post ValueFromPipelineByPropertyName = true.

:

New-Post -Title "Foo" | Set-Post

get accessor Set-Post cmdlet Title :

Stack trace for parameter binding in powerShell

, CmdletParameterBinderController.GetDefaultParameterValue Title Set-Post , .

+3

All Articles