What tends to trip developers up when learning PowerShell?

November 25, 2026 5 answers
Asked by 2x+quartzdrawer_573

I know a few other programming languages and want to get more comfortable writing PowerShell scripts. Which assumptions from other languages are most likely to cause trouble?

Answers

b.759~queldavo

The pipeline usually carries objects, not just lines of text. If a command gives you objects with properties, work with those properties instead of parsing the formatted display with regular expressions.

The display can be misleading because PowerShell often shows only a selection of properties. Try piping a result to Get-Member to see what you actually have. Also, avoid sending objects through Format-Table before further processing. Formatting commands produce formatting data for display, not the original objects.

_f72+quendalo.6:

That distinction helps explain why something can look like a neat table on screen but behave differently when passed to another command.

Reply to this answer
p.418!zanduro

Function output catches a lot of people. PowerShell sends success-stream output to the caller, not just the value following return. A stray expression or a command that emits an object can become part of the result.

Collections can also be enumerated as they move through the pipeline. Test functions with zero, one, and multiple results rather than assuming the caller always receives the same shape.

2x+quartzdrawer_573:

So a function call used for a side effect can affect the result if that call writes to the success stream?

Trelzuno-5q:

Yes. If you don't need that output, you can explicitly discard it, for example by piping it to Out-Null.

Reply to this answer
_p87+torvexa.4

Don't assume execution policy is a security boundary. It's a safety feature that affects when scripts can run, and the effective setting can be controlled at different scopes. Check Get-ExecutionPolicy -List before changing anything, especially on a managed machine.

And when a script won't run, don't jump straight to changing the policy. Check the error first. The path, file permissions, or how the script was invoked could be the issue instead.

Reply to this answer
p.741!zunravo

Aliases are convenient at a prompt, but they can make scripts harder to read and may not mean what someone coming from another shell expects. Use the full command names in shared scripts, and check an unfamiliar alias with Get-Alias rather than guessing from its name.

Reply to this answer
8k+brindlepulley_539

Operators deserve a closer look too. PowerShell is often case-insensitive by default, and type conversion can affect comparisons. A comparison against a collection can return matching elements rather than a simple Boolean, which is a surprise if you're expecting behavior from another language.

Scope and class importing can also feel different from languages built around explicit modules and lexical scope. For anything nontrivial, check the documentation for the specific feature instead of assuming the familiar rules apply.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions