{"id":16562,"date":"2024-01-26T22:24:36","date_gmt":"2024-01-26T22:24:36","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=16562"},"modified":"2024-02-16T10:27:58","modified_gmt":"2024-02-16T10:27:58","slug":"use-process-block-for-pipeline-inputs-ps","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=16562","title":{"rendered":"Use process block for pipeline inputs (PS)"},"content":{"rendered":"<p>If you get a parameter via the pipeline and don&#8217;t use a process block, you will operate just on the last input.<\/p>\n<pre>\r\nfunction PrintFromPipeline {\r\n    param (\r\n        [Parameter(ValueFromPipeline)] [string[]] $InputObject\r\n    )\r\n\r\n    foreach ($Item in $InputObject) {\r\n        Write-Output $Item\r\n    }\r\n}\r\n'1', '2', '3' | PrintFromPipeline\r\n# 3\r\n<\/pre>\n<hr>\n<p>You don&#8217;t even need the foreach loop, cause the process block will be executed for every pipeline input.<\/p>\n<pre>\r\nfunction PrintFromPipeline {\r\n    param (\r\n        [Parameter(ValueFromPipeline)] [string[]] $InputObject\r\n    )\r\n\r\n    process {\r\n        Write-Output $InputObject\r\n    }\r\n}\r\n'1', '2', '3' | PrintFromPipeline\r\n# 1\r\n# 2\r\n# 3\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you get a parameter via the pipeline and don&#8217;t use a process block, you will operate just on the<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[78],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/16562"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16562"}],"version-history":[{"count":9,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/16562\/revisions"}],"predecessor-version":[{"id":16570,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/16562\/revisions\/16570"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16562"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}