{"id":323,"date":"2012-09-06T16:26:39","date_gmt":"2012-09-06T14:26:39","guid":{"rendered":"http:\/\/dev.flauschig.ch\/wordpress\/?p=323"},"modified":"2012-09-06T16:26:39","modified_gmt":"2012-09-06T14:26:39","slug":"powershell-construct","status":"publish","type":"post","link":"http:\/\/dev.flauschig.ch\/wordpress\/?p=323","title":{"rendered":"PowerShell &#8220;|%&#8221; Construct"},"content":{"rendered":"<p>Recently I stumbled on a piece of PowerShell syntax that confused me massively on first glance<br \/>\n<code><br \/>\n$ some-command |% {some-expression}<br \/>\n<\/code><br \/>\nIt took me a while to find the documentation for that since I was of course looking in the wrong place. It looked to me like some sort of special pipe, when in fact it is just a pipe &#8220;|&#8221; followed by the ForEach-Object CmdLet which has an alias that (unfortunately) is &#8220;%&#8221;. So what was actually happening is:<br \/>\n<code><br \/>\n$ some-command | ForEach-Object {some-expression}<br \/>\n<\/code><br \/>\nFor example, I used this to basically fill in some placeholders in a template file<br \/>\n<code><br \/>\n$ Get-Content \"mytemplate.txt\" |% {$_ -replace \"PLACEHOLDER\", \"42\"}<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I stumbled on a piece of PowerShell syntax that confused me massively on first glance $ some-command |% {some-expression} It took me a while to find the documentation for that since I was of course looking in the wrong place. It looked to me like some sort of special pipe, when in fact it &hellip; <\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[113],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-executor","4":"post-323","6":"format-standard","7":"category-powershell-tools"},"acf":[],"views":1780,"_links":{"self":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/323"}],"collection":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=323"}],"version-history":[{"count":0,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/323\/revisions"}],"wp:attachment":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=323"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}