PSUseProcessBlockForPipelineCommand does not recognize use of $input within an End block
See original GitHub issueSteps to reproduce
Invoke-ScriptAnalyzer -IncludeRule PSUseProcessBlockForPipelineCommand `
-ScriptDefinition 'Param([Parameter(ValueFromPipeline=$true)][psobject] $Item); End {$input |ConvertTo-Json}'
Expected behavior
(no output)
Actual behavior
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSUseProcessBlockForPipelineCommand Warning 1 Command accepts pipeline input but has not defined a
process block.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.3.4
PSEdition Core
GitCommitId 7.3.4
OS Microsoft Windows 10.0.22621
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.21.0
Issue Analytics
- State:
- Created 4 months ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
[Repost] PSUseProcessBlockForPipelineCommand does ...
[Repost] PSUseProcessBlockForPipelineCommand does not recognize use of $input within an End block #1915. Open. brianary opened this issue on May ...
Read more >Advanced PowerShell Functions: Begin to Process to End
Use this block to setup the function by initializing objects such as variables, database connections, or arrays that will be used throughout the ......
Read more >public/New-UcmOffice365User.ps1 0.1.2-alpha
This function accepts both parameter and pipline input .OUTPUTS ... "Warning" : User already exists, creation was skipped ... SIG # End signature...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@brianary using $input in the end is not something that we recommend and will likely lead to misunderstandings as the following example shows.
when run, the output is as follows:
As you can see, $input has no value in both the
BEGIN
andEND
blocks anda
has the last value that$a
was set to in theEND
block.This rule is expressing the appropriate expectation that if you have pipelined parameters, you need to handle them in a
PROCESS
block. The rule violation has nothing to do with$input
in theEND
block, only that you have failed to handle the pipeline variable in the appropriate block.@JamesWTruher Yes, you can’t mix
$input
in multiple blocks, as I said, because it consumes the values.