r/PowerShell • Community Blogger • 22h ago

News Why developers hate PowerShell

https://powershellexplained.com/2026-11-24-why-developers-hate-PowerShell/?utm_medium=post&utm_content=rpowershell&utm_source=reddit

This is a post that I have been thinking about writing for a very long time now. I find that developers struggle with PowerShell in a very different way that the sysadmin learning to automate. They bring intuitions and assumptions with them from other languages that catch them off guard when they skip over the documentation. In this article I try to capture some of those experiences and misunderstandings.

I cover a lot of ground in this one: running scripts, execution policy, aliases, objects and formatting, calling functions, output and return values, unrolling, operators, case sensitivity, type conversion, truthiness, strings, scope, automatic variables, paths, encoding, errors, native commands, and classes.

While this one is targeting Software Engineers more then Systems Engineers, I would still appreciate your feedback and stories of your own frustrating experiences.

Thank you, -Kevin

255 Upvotes

74 comments sorted by

View all comments

Show parent comment

1

u/SupremeDictatorPaul 14h ago

Honestly, a lot of array handling in PowerShell is problematic. Like, if a function returns an array, that array gets returned. Unless the array has one object, in which case it gets unrolled. Which means every time you use a function that returns an array (outside of a pipeline), you have to wrap the function in an array to ensure that later code that expects an array doesn’t fail. There are a few situations where it simplifies code a little, but in nearly every instance for me it’s just been a hassle.

1

u/surfingoldelephant 13h ago edited 12h ago

Like, if a function returns an array, that array gets returned.

No, it doesn't. Each element gets emitted individually, even if there are multiple. And the original array is lost. When there are multiple, PowerShell collects them in a new array and uses that as the result (assuming the result is being assigned to a variable).

# Each element in the int array gets emitted individually.
# PS collects them in a *new* object array. The original int array is lost.
$x = & { $a = [int[]] (1, 2, 3); $a } 
$x.GetType().Name # Object[]

When there's only one emitted object, then yes, the result is just that.

If you're the function author, Write-Output -NoEnumerate or using a throwaway array is how you guarantee array output so the caller doesn't need to wrap in an array themselves.

# Array created by the unary comma gets discarded,
# so output is the original int array.
$x = & { $a = [int[]] (1); , $a } 
$x.GetType().Name # Int32[]

Generally though, I'd avoid doing that as it breaks PS's item-by-item processing, which is the main reason for "unrolling" arrays to begin with. Functions should generally be emitting objects individually as soon as they're available and not collecting all objects upfront, so that they can participate properly in a pipeline (which is how almost every command shipped with PS behaves).

1

u/dodexahedron 13h ago edited 11h ago

There's also the -NoEnumerate switch, which is for exactly that. But using it can also be clunky.

Also, note that passing an array object through the pipeline as input to the next pipeline stage enumerates by default but, if passing that object as an explicitly named parameter (even from the pipeline), it stays an array, always.

Strongly type your parameters and write pipeline-friendly code in the first place (i.e. make use of begin, process, end, and clean as appropriate - including in ad-hoc/ in-line script blocks), and it won't be an issue.