Top
Best
New

Posted by corbindavenport 1 hour ago

I can't believe PowerShell is good(www.spacebar.news)
36 points | 15 comments
d3Xt3r 19 minutes ago|
Windows sysadmin here. PowerShell has been great for a long time, well, since at least v5.1, when they finally fixed many of the annoying issues and limitations of earlier versions. I practically live in it the whole day - 90%+ of my work life is in PowerShell these days.

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.

majkinetor 8 minutes ago|
You can fix that very easily in your linux profile (make ls call gci and not native tool). Just add alias in your profile. You cant really complain about the absence of some cmdlets on linux, and they are trivially easy to get implemented (or wrap native tools).
3eb7988a1663 37 minutes ago||
I have only ever used Powershell when I had no other options, but a decent number of the APIs feel designed by someone who has never used a terminal. Like they were begrudgingly fulfilling the objective without ever imagining a real use-case.

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.

xp84 31 minutes ago||
I have to admit it's better than scripting in Bash, but in my personal opinion that's a bar so low it's on the ground. Don't get me wrong, I'm grateful that shell scripting is a thing. But my policy for a decade has been that when I need any logic more complex than a simple string matching in an `if`, I should back away from the computer and then rewrite it in a reasonable scripting language.

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.

pasc1878 13 minutes ago|
Only a decade ?

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)

majkinetor 13 minutes ago||
Powershell is so good that I find it strange it didn't get to be default at least in some Linux distributins (or some proper fork/redo of it). I even used it for integrative feautures for some of my state projects serving millions of user. The fact that I have proper language, designed for shell, very efficient, not needing an IDE or anything, is quite liberating.

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).

Script 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.

holysoles 20 minutes ago||
I've written a lot of powershell in my time..

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...

SBArbeit 35 minutes ago||
Part of setting up a new Windows or Linux machine for me is installing the latest PowerShell 7+.

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.

stephbook 17 minutes ago||
PowerShell is nice. It also reads well. What does sed, tar xvf, jq curl -k actually _do_?

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.

Panzerschrek 10 minutes ago||
Does it have automatic error handling, so that if one command fails, the whole script fails too? Last time I tried it, I needed to write

   if ($LastExitCode -ne 0)
after each command.
ruined 40 minutes ago||
unlike macos's curl, powershell's curl alias for Invoke-WebRequest checks the revoke list and will protect you from mitmproxy --emudhra
Superbowl5889 36 minutes ago|
Why doesn't curl check revoke list.
ruined 35 minutes ago||
i don't know, man. i don't know.
IronWolve 11 minutes ago|
Been using oh-my-posh in powershell, and some aliases to map commands for my old linux sysadmin brain. Everything mostly works to get the job done, even got vi and scp. Its just another tab in my windows terminal with my ubuntu tabs.