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{
        $CertifiedName = (Get-ComputerInfo).$ThingThatNeedsFixin
        Write-Host "$FixerUpper is going to fix the $CertifiedName!"

\\\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'
FixIt Function
But lo and behold an error awaited me on the other side of the terminal. At least I think it was an error. Instantly I had worries of inflation and share dilution and contemplated selling my scripts at a fraction of what I paid for them, but I pushed those thoughts out of my head and went back to the drawing board.

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:

FixIt Function 1
To Here:
FixIt Function 2
And try, try, and try again:
FixIt Function (Working)

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.


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!


Nested AD Managers (PowerShell)

So I had a somewhat odd request (isn't that how all truly great stories start) a long time ago in an IT galaxy far, far away. And it went something like this: we want to email an employee and CC their manager, but if their manager is inactive (took a one-way trip to...

6 Things I Wish I Had Known About PowerShell

About a hundred years ago when I stopped riding dinosaurs to work and started learning PowerShell, I struggled to know what to learn first and where to even begin. That blue box with white writing was intimidating to say the least. I finally worked up the courage to...

Index Scripts for Windows Search

So you just finished writing some code and you go to save your file. You summarize all of the important aspects this section of code contains into a nice, easy-to-read file name that your future self will immediately recognize. Fast forward to the future where you...

Array vs ArrayList (PowerShell)

For some tasks in life, being precise is a necessity. But most of us get away with rounding, paraphrasing, and hitting in the general vicinity most of the time. Depending on your personality, you may be one who strives for perfection and strains on every miniscule...

Spice Up HTML Emails with PowerShell – Part III

So far in this series we've fumbled our way around the kitchen and tried to wing it when sending HTML emails with PowerShell. It was clunky to say the least. We then went through our spice rack and built an HTML template, highlighting the nuances of each spicy element...