I can't believe PowerShell is good
Posted by corbindavenport 9 hours ago
Comments
Comment by d3Xt3r 8 hours ago
But I question its utility on other platforms, because a lot of the things that makes PowerShell cool on Windows doesn't actually work in Linux or macOS.
Eg: Get-Service (and associated cmdlets). Very handy cmdlet that I use all the time on Windows. On Linux, you'd expect that it'd work with systemd units, but no, that command doesn't exist on the Linux version. Same with Get-NetAdapter, or Get-NetTCPConnection, or Get-Disk and so many other handy cmdlets that I use all the time on Windows, are all missing.
Yet, some cmdlets do exist, like Get-Process or Get-Uptime etc, so I don't understand why many of the commonly used Windows cmdlets haven't been ported over.
Another annoying quirk is how PowerShell on *nix hands off some of the built-in aliases to their native versions. Like on Windows, I always use 'ls' because ain't nobody got time to type Get-ChildItem. Unfortunately when I run this on *nix PS, it runs the native version. And this is a problem because when I pipe 'ls' into a for loop or another cmdlet for further processing, it naturally, doesn't work. To make things worse, this native-or-alias decision making isn't even consistent. Like 'pwd' for example actually runs the PowerShell version, whereas 'echo' runs the native version.
Basically, as much as I love PowerShell on Windows, on *nix it is very annoying to work with. I would much rather work with native *nix shells and scripting languages. And if I really wanted the structured output of PS, I would run Nushell instead, which is far more consistent and useful than the half-baked product that *nix PowerShell is.
Comment by tressure 7 hours ago
Comment by d3Xt3r 7 hours ago
Comment by majkinetor 6 hours ago
its faster then this discussion.
Comment by d3Xt3r 5 hours ago
Comment by majkinetor 5 hours ago
You can ask AI now to do it for you, you can probably find easily something somebody already did. It would have been nice if MS offered something that people can choose to install, but its far from a deal breaker like you seem to make it to be.
There is nothing to test, you want collection of aliases, that is trivial.
FWIW, they tried some things like https://github.com/PowerShell/Crescendo
Comment by d3Xt3r 4 hours ago
And why should I waste my AI tokens on fixing Microsoft's product? I'd much rather contribute my resources towards a fully open-source, indie project.
Comment by majkinetor 4 hours ago
Comment by majkinetor 8 hours ago
Comment by d3Xt3r 7 hours ago
If you want me to fix up Microsoft's slop, I'd rather contribute to a proper indie FLOSS project, like Nushell or something.
Comment by majkinetor 6 hours ago
Its not slop for one. Take a look at repo and its practices. Its mind blowing and predates AI.
Nushell is nice, but lets not get carried away - it is decade away from pwsh, and suffers from the same things you complained, with language and semantics that are not intutive as pwsh's and not nearly as complete. Besides, so many 3rd party supports pwsh like Sql Server, VMware etc.
I agree that MS should push it way more and make Linux variant even better. The problem is that pwsh hardly surived at MS (cudos to Snover for being stuborn and worked against his position at MS to make it happen), and that needs some opinionated people working in MS who can fight this battle (I could honestly dedicate my life to this, I offer my services, for both pwsh and Windows, Microsoft!).
Comment by oblio 8 hours ago
The web was successful because the installation cost was 0.
Comment by majkinetor 7 hours ago
Comment by 3eb7988a1663 8 hours ago
Naturally, I cannot produce an example off hand, but I was pretty disappointed the last time I had to reach for it and found that a few "obvious" workflows seemed more hacky than I would have expected for a clean-slate terminal language design.
Comment by orbital-decay 7 hours ago
Calculators had the same problem when they got too powerful for their own good and feature creep made them outgrow their use case in the world of personal computers (see TI or modern advanced calculator apps like Qualculate). They're pretty awkward compared to HPs that were designed for expressing a simple problem in fewest keystrokes with great attention to detail like interactive inversion and repetition.
Comment by retromagik 7 hours ago
Test-NetConnection -ComputerName dns.google -TraceRoute
Comment by majkinetor 6 hours ago
tnc dns.google -t
I didn't even have to look for the alias, there is standard naming for them.Like I said before, people who complain just didn't RTFM and got out of their comfort zone.
Comment by beng-nl 7 hours ago
Comment by Dedime 7 hours ago
Comment by pjmlp 6 hours ago
Comment by orbital-decay 6 hours ago
Comment by pjmlp 6 hours ago
Comment by cherrychon 7 hours ago
Comment by majkinetor 6 hours ago
Comment by bulbar 7 hours ago
Comment by 16bitvoid 7 hours ago
Comment by majkinetor 8 hours ago
I use it for all kinds of stuff. Here is an example that creates MusicBrainz collection from my local audio folder, solving the browsers proof of work in between: https://github.com/majkinetor/musicbrainz-userscripts/tree/m...
If I am nitpicking, performance could be better, although MS did a lot in previous years and even that just in theory as I was never really blocked by that. But if it could be performance beast too, I would think we can stop researching new shells and just use it everyhwhere.
JSON support is amazing - you don't learn anything new like with jq, it just works. Selecting stuff is amazing, I love it more then SQL. HashTables are epic for configuration (you have a real language in it, unlike in lets say YAML).
Scripts that look horrible in bash are few lines of beautiful in pwsh.
If you didn't try it, or didn't give it a chance, you are missing out for sure.
Comment by 3eb7988a1663 7 hours ago
I believe nushell is the closest Linuxy Powershell implementation with structured data.
Comment by majkinetor 7 hours ago
Comment by Schlagbohrer 7 hours ago
Comment by kstrauser 7 hours ago
It feels like the difference between old-timey classical English vs street talk. "Greetings, dearest companion, how fare you this fine Autumnal day?" is a lot of syllables for someone you're familiar with. "Hey! Enjoying the day?" says the same thing, but conversational. There's a time and place for the former, mainly when writing dialog set in 1500 or something. I'd much rather say the latter when bumping into my neighbor at the cofee shop. Similarly, I could see why someone might want to write
Get-ChildItem -Filter *.txt -Force
in a script so that it's clear-ish what that means later, but if I'm spending my time in a terminal, I'd vastly rather learn what ls -la *.txt
means. It's terse to the point of inscrutability, and not beginner friendly at all, but once you type it a few thousand times it's second nature.All things considered, I'll stick to Fish, thanks.
Edit: Related, but once I learned how Unix shells typically expand globs, that feels like the right layer for handling that and similar other things. "ls" doesn't know what a glob is. When you type "ls -la .txt", the shell* expands that into a list of matching files, like "ls -la foo.txt bar.txt baz.txt", then "ls" operates on each one of those in turn. You don't have to teach every program how to interpret globs. The shell has to learn that, once, then every other program automatically benefits from it. Type "echo *.txt" and you'll see the list of matching names. Echo has no idea what that means. It only knows that it got a list of worlds to write out with no idea where it came from. I think Bash/zsh/fish/etc. do this the right way, and that implementing that in every tool is the wrong way. It just feels weird and inefficient and prone to have odd, subtle deifferences.
Comment by Schlagbohrer 3 hours ago
Or with Boston compression active: "Heyhowarya"
Comment by __d 2 hours ago
Unix used to have a glob command, rather than building it into the shells (and the C library). I think it was 7th edition that added it directly to Bourne shell.
Comment by majkinetor 6 hours ago
With longer commands, auto complete is also viable. I hate some long forms, like % vs ForEach-Object and ? vs Where-Object, its just ludicrious that someone would insisit in using full forms of those.
Things like `ps | ? name -like w*` or `1..10 | % { irm https://.../$_ }` can't really get shorter and I use them all the time
Auto complete on params is epic. Type -e and ctrl space to see all params starting with e along with their aliases. Verbosity is good thing in that case, as -ea doesn't mean much when you are new to this.
ps -e<CTRL+SPACE>
ErrorAction ea ErrorVariable ev
The verbose practice is not meant for interactive use, but for sharing scripts.Comment by LeonB 7 hours ago
Comment by fulafel 7 hours ago
Comment by majkinetor 6 hours ago
Comment by Schlagbohrer 7 hours ago
Regarding the article: Corbin Davenport is an amazing name. Nice article too.
Comment by cherrychon 7 hours ago
PS> Get-Help -Name 'InsertName' -Full Shows the Help, can be Imported/Created via XML 4 New Modules PS> Update-Help -UICulture en-US Fetches & Installs Help Files in English
Hope that helps!
Comment by bulbar 7 hours ago
Have you never used a Linux distro? I always end up with two windows managers, two login managers, 2-3 shells, 2-3 package managers and what not.
Comment by jval43 6 hours ago
One saving grace with Linux distros is that usually the maintainers package versions that are compatible with each other. So if you stay with the default repos things work.
But yeah once you install newer versions from non-distro repos it might be fine (e.g. git) or things will break in subtle ways.
Comment by Brian_K_White 5 hours ago
You can have multiple different sh's, but you have to go out of your way to force them to be used. And evenn if you did, dash and ash and older versions of bash and sysv sh are a strict totally compatible subset of latest bash, and none ever has the problem of incompatible or missing modules or plugin library. Old scripts work in new bash.
The python to powershell comparison was valid. This false equivalence was not.
The fact that you can have 2 window managers is like having 2 mp3 players. It's not the critique at all.
Comment by holysoles 8 hours ago
PS is really powerful for Windows OS level concepts and enterprise software that have good modules (AD, IIS, Citrix). However it has so many semantics that can burn you; non-strict mode, implicit type conversion, ordered null checks [1], not to mention the amount of boilerplate in a module and the runtime overhead. At a certain scale/complexity you need to graduate to using C# and .NET.
[1] https://learn.microsoft.com/en-us/powershell/utility-modules...
Comment by jayd16 7 hours ago
Comment by SBArbeit 8 hours ago
My $PROFILE has custom modules that comprise ~9,000 lines of PowerShell. Anything "script-y" that I think I'll do more than a few times becomes a new function in one of those modules.
On Windows, I haven't used `cmd.exe` in at least a decade.
And part of my root `AGENTS.md` is "Please use PowerShell when generating scripts, unless I specifically ask for a different language."
Works a treat.
Once you get used to passing objects between commands - not just text - the thought of using a Unix-y shell feels like visiting the past.
Comment by xp84 8 hours ago
Powershell is definitely a reasonable scripting language; it's mainly its verbose command names and new-to-me syntax that have made me put off learning it so far. I suspect that it looks more familiar and welcoming to .NET devs though.
Comment by pasc1878 8 hours ago
Perl python tcl have been around for over 30 years. Anyone writing in bash/sh etc is producing unmaintainable line noise (and I was a perl and APL programmer)
Comment by jval43 6 hours ago
I totally get it for people who only ever used .BAT files (our entire IT department at work). It must feel like a godsend to them. Bash of course never worked for these people; running it on Windows via MinGW/Cygwin is just a bad experience.
But the relentless bashing of Bash itself and the longstanding Linux (and Unix) ecosystem alternatives in general is unjustified in my opinion.
Bash itself is elegant, powerful and concise, and just works on Linux. You can write spaghetti code, but you don't have to. Readable scripts are just as easy. "Skill issue" if you will.
And yes, Bash-isms exist, and I got reminded of that fact when Ubuntu shipped Dash as the default /bin/sh shell for a while or when I'm on macOS. But it's really not a huge deal: just use the real !#/bin/bash and ignore the "um actually in Posix..." complainers on the internet.
I do appreciate that Windows finally has a capable scripting language, and while I don't like the lengthy syntax / cmdlets, I also see some benefits. But Bash is still great nonetheless.
Comment by ibramGaunt 6 hours ago
It's a much more powerful system, but users who are used to being able to do, well, whatever they want with no rules get frustrated with the syntax and "correct way" to do a thing when you just want a stupid string (it's me I'm users). It's very similar to Rust in that way, where once you stop fighting the borrow checker life becomes so much easier; once you stop fighting the objects, you stop getting in your own way and it becomes a much more productive experience.
Comment by eddythompson80 7 hours ago
On the other hand, the considerable slowness or JIT lag kills me. Same with the crazy verbosity of everything. You end up setting up so many aliases that your shell ends up being very very different from any other pwsh. I setup or expect a lot of aliases on bash too, but pwsh is multiple orders of magnitude that. Like I always hate when I ssh to a machine and something as simple as `ll` doesn’t work and I need to spell out `ls -alh`, but with pwsh it’s EVERYTHING. Until very recently simple things like -e didn’t exist.
But the slowness is what really kills me.
Comment by stephbook 8 hours ago
And then passing text lines with > like a caveman. Does bash not have the concept of objects?
You write Invoke-WebRequest and it invokes a web request. Easy.
Comment by static_motion 7 hours ago
The language designers managed to introduce the ambiguity of natural language into a shell scripting language. As a developer, I think that it makes PS wildly unergonomic and I find it easier to remember bash/Linux idiosyncrasies.
Comment by schoen 7 hours ago
If I remember correctly, AppleScript was inspired by HyperTalk, which also mainly used English keywords in English-inspired syntax, but most HyperTalk wasn't valid AppleScript, and vice versa.
Comment by delis-thumbs-7e 6 hours ago
And PS is pretty good, although I haven’t used used PS7 much (if it is a completely new application, why does it share a version number? And why does it not come as the default shell with Windows? Why do they have to make everything so confusing?). It is probably nicer for extended scripting than bash, but honestly I rather use Python for that. For windows admin stuff it is great, but mostly I work with network stuff and it is way too verbose to my taste for simple commands. ping is a lot easier to remember than Test-Connection. I reach for cmd commands like netsh int set ip rather than tab through the verbose syntax of PS for simple network commands. I know you can set up aliases and bash aliases like ls work, but I still feel it os pretty impractical for quick terminal work.
Using it on linux feels so blashemous that I will not entertain such vile and fevilish thoughts. I use linux to get away from the sinful awful things I must do for my livelihood, I tather not use Win applications on my own system unless I absolutely need to. For any serious scripting on Mac… Maybe just don’t?
Comment by ruined 8 hours ago
Comment by cherrychon 7 hours ago
No Idea what MacOS ships with but I'd mistrust that. But if you're running shell scripts...
Comment by Superbowl5889 8 hours ago
Comment by ruined 8 hours ago
Comment by BoppreH 7 hours ago
Life is too short for parsing ad-hoc data formats from the 80s, and the "everything is a string" approach from *nix is a major contributor for the unreliability of shell scripts.
Comment by dexterlagan 5 hours ago
Comment by bob1029 7 hours ago
Powershell is still indispensable for things like deploying build artifacts to production servers. Anything where you need to provide a secure command link between two windows boxes.
Most of my GitHub actions are a thin yaml wrapper around az login and powershell session setup. From that point 99% of the magic resides in a proper C# codebase.
Comment by Panzerschrek 8 hours ago
if ($LastExitCode -ne 0)
after each command.Comment by badlibrarian 7 hours ago
Great tool for Windows admins who haven't realized they can write quick and dirty C# scripts cross platform for a decade now.
Comment by 2d8a875f-39a2-4 6 hours ago
Eye-bleed syntax, but I guess my agents don't mind that.
Comment by tosti 2 hours ago
$input = <STDIN>;
chdir "~/Desktop";
system("yt-dlp -x --audio-format mp3 $input");
And have you seen errors in powershell? Bill Lumbergh would like such a verbose report, not me.Comment by globular-toast 7 hours ago
Comment by IronWolve 8 hours ago
Comment by nonameiguess 8 hours ago
It didn't revolutionize my life, though. Three years later, I no longer use Windows for anything and revert to plain POSIX shell whenever possible for all scripting, largely for ecosystem reasons. Everyone else I work with is using that. I'd analogize this to challenges living downtown in the middle of a busy city. My roads are terrible, largely because they're so patchwork due to utilities and construction teams needing to tear out pieces, fix or add something underground to accomodate new building, then put the road back together again. It means you'll have 30 meters of regular concrete, then 10 meters of asphalt, then 20 meters of some pebbles in glue looking monstrosity. It works well enough for cars with large rubber tires and suspension systems, but it's hell for skateboarding. Go out to the suburbs where the entire road is all the same substance and it's smooth sailing.
Hacker News and the web more generally seems like these discussions about tooling and dev experience end up dominated by solo developers. If you're the only person working on a project, let alone these days with LLMs where half the breathless posts are about software where you're not only the sole developer but also the sole user, do whatever you want. It's like moving all the furniture around in your room every single day when you live alone. Go for it. But if you have a spouse, whether or not your new design is better than the old one, that's kind of rude. When you're part of a team, you have to eventually settle on all doing roughly similar, predictable things so you're not disrupting everyone else's workflows and expectations, even if those roughly similar, predictable things are suboptimal and there's a better way.
Comment by bloaf 7 hours ago
But being technically capable of something and being good at something are different.
Powershell tried so hard to be user friendly that it wrapped around and ended up being user hostile. There are far too many footguns and "magic" features that do nothing but sit around and wait for you to forget about them so they can break everything.
Just look at the comparison -eq as an example. First off, this is the same syntax powershell uses for named function arguments. Why on earth would you do this? Because operators like this exist, I now need to ask myself "is this a named function argument, or was the script author trying to use an operator here?" for EVERY NAMED ARGUMENT. But wait! That's not actually true! After all, powershell has two ways to call functions. Because powershell is like the red-headed stepchild of the other dotnet languages, when you want to call functions on assemblies, you can use a more conventional
[complex.syntax]::F(x, y)
So there you can use normal named arguments without having to second guess what they are right? Haha no jk powershell doesn't have a syntax for calling a C# function with named arguments, you just have to work out the positions and pass null (sorry, I mean [type]::Missing) in for any optional named parameters you didn't mean to supply a value for.
ANYWAY, back to the -eq operator. You might THINK that an equality comparison operator would return a boolean, but that is because you are not as smart as the PowerShell devs. The powershell devs know that an -eq operator should actually act like a filter if the left hand side is a list, returning the elements of the list that match the right hand side. Now in my head, this is the most astonishing behavior (least astonishing is just returning false if the types don't match, next up is a list of {true, false, ...} that comes from from mapping the comparison across the list), but that is because I am not as smart as Bill Gates.
Now you could maybe defend this behavior if it were easy to keep track of your types in powershell. But powershell actively makes this more difficult by doing things like automatically converting [int] into plain int when the array only has one item in it! So because powershell tries to be helpful and give -eq more power, then also tries to be helpful by unwrapping your one-item-lists because surely that's what you want, you can very quickly find yourself in a situation where you the scriptor are finding bizarre errors caused by having -eq insert lists of things where you expected booleans to be.
This kind of combinatorial-inconvenience is pervasive in powershell.
I'm all for "lets make an object-oriented scripting language", but there are so many unforced errors in the powershell language design that its hard to recommend.
Comment by Brian_K_White 4 hours ago
It's always trying to adapt to the driver, but that is a fundamentally invalid concept.
I think there is (or should be) a principle that in any given system there can only be at most one spongy dynamic reactive element.
Everything else needs to be deterministic.
In a car, the human driver is unavoidably a spongy dynamic element, so the only slot available for one of those is already taken. You can't have both a driver trying to game the car and the car trying to game the driver at the same time.