For all of you who are still out there working because you missed becoming a DOGEionaire and therefore still have your job in IT, this post is for you. And as it’s clearly evident by me writing this post…I did not catch that sweet meme train to the moon. Before we all start grumbling about missed opportunities, let’s take a look at some code. At work recently I was writing a simple function for something I wanted to turn into a one-liner in the future and I ran into a conundrum: that cursed ValueFromPipeline parameter settings in PowerShell. Don’t get me wrong, I actually like that blasted thing but today it was besting me like the hedgies have been doing for months now.
\\\What had happened was
First, let’s talk about what happened. There I was, minding my own business, shelling out power quicker than you can mine a bitcoin and I ran into an error. Let me just segue right here into my theory that if the error messages were colored green instead of red there would be a lot less anxiety in the IT world…but that’s a discussion for another day. If you’re unfamiliar with the ValueFromPipeline parameter attribute, in a nutshell it allows you to pass a value from the pipeline to this parameter in your function. It’s really useful for getting something with one cmdlet and then piping it to the next cmdlet to do something with it. I’ve used this hundreds of times before and this was the first time it wasn’t working for me.
So I did what any good IT professional would do: I kept pressing enter thinking it would fix itself.
…
After about half a day of doing that and getting nowhere, I decided to actually look at my code. This wasn’t my actual code (or was it?), but here’s an example of what I ran into:
function FixIt{
[CmdletBinding()]
Param(
$FixerUpper,
[Parameter(ValueFromPipeline=$true)]
$ThingThatNeedsFixin
)
Begin{
$CertifiedName = (Get-ComputerInfo).$ThingThatNeedsFixin
}
Process{
Write-Host "$FixerUpper is going to fix the $CertifiedName!"
}
End{}
}
\\\Stonks Only go UP
Since my parameter $ThingThatNeedsFixin accepts value from the pipeline, I expected to be able to do something like this:
'OsManufacturer' | FixIt -FixerUpper 'Felix'

What’s worse than an error message written in red ink? No error message at all. I checked all of my notes, googled ValueFromPipeline to make sure I had typed it correctly, and even buried myself in multiple volumes from the Library of Alexandria to no avail. What was I missing? Everything looked right…but it still wasn’t working.
\\\Bull Trap
Finally, I found my issue.
Well, one of my issues. I still have plenty of other ones.
If we move this line from here:



Well I Musk say, it worked! I went back to the BEGINning and found the culprit! I was today years old when I learned that the ValueFromPipeline only works in the Process block of a function…not the Begin block.
\\\ID10T
And for all of you out there shaking your head at me…yes, I know it makes perfect sense when you stop and think about it. The Begin block of a function runs once and the Process block exists to loop through each value piped to it when you set a parameter to allow values from the pipeline. Duh! I mean, of course it wouldn’t work in the Begin block…I had just never made that mistake before so I was lost for longer than I care to admit. I think it was the DOGE FOMO getting to me.
Maybe you already know this and you learned absolutely nothing from this post. Or maybe this will help you in the future and save you some time writing advanced functions in PowerShell. In either case, let’s go the MOOOOONNNNNNN BABBYYYYYY!