0
0
PowerShellscripting~10 mins

Pipeline input (ValueFromPipeline) in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to accept pipeline input for the parameter.

PowerShell
param([Parameter(ValueFromPipeline=[1])]$Name)
process { Write-Output $Name }
Drag options to blanks, or click blank then click option'
AFalse
B$false
CTrue
D$true
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'True' or 'False' without the $ sign causes errors.
Setting ValueFromPipeline to $false disables pipeline input.
2fill in blank
medium

Complete the code to process each pipeline input object.

PowerShell
process {
    Write-Output [1]
}
Drag options to blanks, or click blank then click option'
A$PSItem
B$Name
C$input
D$null
Attempts:
3 left
💡 Hint
Common Mistakes
Using $input returns all pipeline objects, not the current one.
Using $null outputs nothing.
3fill in blank
hard

Fix the error in the parameter declaration to accept pipeline input by property name.

PowerShell
param([Parameter(ValueFromPipelineByPropertyName=[1])]$Age)
Drag options to blanks, or click blank then click option'
AFalse
BTrue
C$true
D$false
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'True' or 'False' without $ causes syntax errors.
Confusing ValueFromPipeline with ValueFromPipelineByPropertyName.
4fill in blank
hard

Fill both blanks to create a parameter that accepts pipeline input by value and process it.

PowerShell
param([Parameter(ValueFromPipeline=[1])]$Item)
process {
    Write-Output [2]
}
Drag options to blanks, or click blank then click option'
A$true
B$false
C$Item
D$null
Attempts:
3 left
💡 Hint
Common Mistakes
Setting ValueFromPipeline to $false disables pipeline input.
Outputting $null produces no output.
5fill in blank
hard

Fill all three blanks to accept pipeline input by property name and output the property value.

PowerShell
param([Parameter(ValueFromPipelineByPropertyName=[1])]
      $Name)
process {
    Write-Output [2].[3]
}
Drag options to blanks, or click blank then click option'
A$true
B$false
CName
D$PSItem
Attempts:
3 left
💡 Hint
Common Mistakes
Using $false disables pipeline input by property name.
Using $Name alone inside process does not access the pipeline object.