5 ms·
PowerShell: The object-oriented shell you didn't know you needed
- tester457 3y agoI rather nushell for this purpose, it's more fun to write and easier to read. https://www.nushell.sh/ https://www.nushell.sh/
- kej 3y agoThis is what I've moved to lately. I like the idea of structured data but PowerShell just feels like a shell designed by people who don't really want to use a shell.
- notesinthefield 3y agoId posit thats exactly what they want. I started my career using 100% Linux-based tooling and slowly moved into Windows land - I have not ever liked Bash, only tolerate Fish, love Powershell. Ironically I think its biggest limitations are Windows’ fault. They want to latch on to the old point and click guard.
- canadianfella 3y agoI think you mean “prefer” and not “rather”.
- albertopv 3y agoNo deb package though
- chasil 3y agoPowershell's fatal flaw is size. The Debian dash POSIX shell can compile under 100k on i386. This is a space where Powershell can never be.
- dekhn 3y agopowershell is a 440k executable on my machine. functionally, it's much more capable than dash. I don't think powershell is even remotely interested in competing in whatever space you are in.
- jborean93 3y agoPowerShell also needs all the other dll's located next to the executable so it's way more than 440k. Granted I agree that this isn't a space they really care about and the problem is more due to the dependency on .NET itself.
- dekhn 3y agoWell, I assumed the 100K dash shell also was dynamically linked (presumably to libc and the linker loader). But yes, you're right, I wasn't including all the DLLs and all the various modules/scripts you can invoke. from my inspection, it looks like DLLs that are probably already loaded just by booting a system.
- jborean93 3y agoIt's more for pwsh (7+) as that bundles it's own copy of the .NET runtime. The powershell.exe (5.1) is the version included in Windows and uses a shared copy of the .NET Framework included in the GAC. When looking at the size of modern PowerShell (7+) you do need to take into consideration the size of the .NET runtime which is quite sizeable. Personally it's not a problem for me and while I don't agree it's a fatal flaw it's certainly a downside compared to other shells.
- davidmurdoch 3y agoDo you actually care about this?
- tyleo 3y agoTBH I’ve despised the object oriented parts of PowerShell… and it’s been my primary shell for a decade. I just mainly use it with text.
- Aloha 3y agoSorta agree - I'm mostly doing string handling and parsing on windows boxes - so I often just want it to compare on a string or whatever. But sometimes the "everything is an object" is useful in ways that would be really hard to do on unix like systems.
- pdntspa 3y agoPowershell's syntax is so fucking weird and verbose. I guess if you live in Microsoft land all day and write code in C# it's fine, but I would really like it if we all could collectively agree on one set of syntax rules. I don't even care what they are. But as a polyglot I am so sick of having to learn yet another syntax. cmd.exe does everything I need to and batch is actually kind of flexible. Also, I don't know what it is with shell programmers (and I've worked for one) but bash syntax is similarly insane. I am so glad I've never had to write an init.d service because 20 years into my linux career I still can't read that shit. Like I can launch and fork a process in like 10 lines of C, but it's five pages of gobbledygook shell script?
- gwervc 3y ago> I guess if you live in Microsoft land all day and write code in C# it's fine I write C# daily but I'm not fine with powershell syntax. It seems harder than it should be.
- Aloha 3y agoI always joke and PowerShell must have been created by someone who types 300 WPM ;-)
- doubloon 3y agothats what Copilot is for. You just go "please tell me how to work this grep | awk command in powershell"
- dpkirchner 3y agoIs there a cmdlet that will do this automatically?
- pdntspa 3y agoI kind of see these AI tools like a superhero's toolbelt -- great, when it's on you. But one doesn't always have the luxury of internet access. It is best not to overrely on AI, or any cloud service for that matter.
- mattbee 3y agoYeah it's pretty good! I wrote a few hundred line build script for a Windows project last month. I knew no powershell last month, and now it makes more sense to me than bash which I've used badly for 25 years. Actually on Linux I tend to use Ruby for any non-trivial scripting, and it feels much closer to that. So it's probably no coincidence that I've got on with it.
- TheRoque 3y agoCool, but it still can't properly autocomplete anything so I'll try to get that working first
- oscillatingpie 3y agoIt ships with PSReadline now which gives it bash like autocomplete.
- TheRoque 3y agoIs it something to install separately ? Or I need to upgrade something ? I never got it to auto complete anything to be honest
- jborean93 3y agoIt's been shipped with PowerShell since v5.1 (Windows 10/Server 2016). There have been numerous updates to PSReadLine since then to add more features but tab completion has worked for years and is IMO one of the biggest selling points.
- TheRoque 3y agoWeird. Coming from the fish shell, I can't really get anything completed with PowerShell. Mostly, I want it to work with my git commands (detect my branches for example).
- jborean93 3y agoAh if you want auto completion for native commands they need to be registered first. PSReadLine provides autocompletion support but it only works by default with things builtin to PowerShell itself. For `git` there is a fairly popular module called posh-git [1] that provides auto completion support for some of the well known commands. Git for Windows also calls it out [2]. You can also provide your own custom auto complete calls with Register-ArgumentCompleter [3]. Hope this helps! [1] https://github.com/dahlbyk/posh-git https://github.com/dahlbyk/posh-git [2] https://git-scm.com/book/ms/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Powershell https://git-scm.com/book/ms/v2/Appendix-A%3A-Git-in-Other-En... [3] https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/register-argumentcompleter?view=powershell-7.4 https://learn.microsoft.com/en-us/powershell/module/microsof...
- geenat 3y agoHonestly bash would be fine if the control structure syntax was a bit more sane. (... and set -euo pipefail was default). Bash scripts can be tiny for what they do, and the ssh integration is unmatched. xonsh is nice but it's been unstable for me lately. nushell is nice but not sure if it's worth switching the default for.
- felsokning 3y agoPowerShell is great -- but there are some things you simply cannot do with it. For example, try to escape '$', which can be included in urls but can't be used in Invoke-RestMethod. Bash via WSL saves the day, in this regard (e.g.: $results = wsl ./myAwesomeBashScript.sh). While PowerShell is great as object-oriented scripting, it still can't handle simple tasks that can be done in the likes of bash, zsh, etc.
- jborean93 3y agoTo escape $ you either need to use a single quoted string so the $ is treated literally or in a double quoted string use a backtick before the $ to escape it Write-Host 'Foo$Bar' Write-Host "Foo`$Bar"
- RajT88 3y agoA lot of people's complaints in this thread are because they just haven't figured out the powershell way of doing that thing. Granted - the Powershell way of doing some things is stupidly obtuse sometimes.
- felsokning 3y agoIn the issue I ran into, the '$' comes back from Azure in the nextLink[1] value. As soon as you try to process the string, the reserved token '$' breaks any processing - precisely because it wasn't escaped before being stored. Perhaps, it's easy enough to do some .NET manipulation, just to get PowerShell to be able to handle the string for the next Invoke-RestMethod -- but its far easier to just curl those urls, instead. [1] - https://learn.microsoft.com/en-us/rest/api/keyvault/keyvault/vaults/list?view=rest-keyvault-keyvault-2022-07-01&tabs=HTTP#examples https://learn.microsoft.com/en-us/rest/api/keyvault/keyvault...
- swozey 3y agoI have tried many, many times to work with posh. I was even a very senior windows engineer at some of the largest webhosts when it came out and used it heavily because the fantastic Windows Server operating system comes with literally no tools any bsd/nix engineer expects, you know, like rdp brute force detection blockers to actually manage servers, or .. my gosh, IIS URL REWRITES. BFD isn't "baked in" to linux but nobody is hiding their secret sauce so every company has to roll their own vs pulling a package from apt for bfd, etc. Here's your $expensive$ Windows Service license, now spend $20k in dev hours for someone to write a powershell script that monitors eventvwr for failed rdp event errors, extract the ingress ip into a db and block across the board. I remember being fascinated by its history because the main guy wrote it, Jeffrey Snover, I'm going to butcher this, but IIRC he was some sort of big posix/shell/bash/perl/something-very-shell-important and wanted to take the best of whatever systems he was familiar/contributed/wrote and improve them and make that powershell. Anyway, yeah I absolutely despise using it. It's syntax is atrocious. It's key words aren't memorable in the least. I know some people absolutely love it, even people who aren't using it in Windows. But it's never clicked for me. I found this thread interesting. I guess Snover left MS after 23 years there in 2022, and he was demoted at some point after creating powershell. I don't care enough about it to dig into why but if anyone is interested- https://news.ycombinator.com/item?id=31302174 https://news.ycombinator.com/item?id=31302174 I did windows engineering at the biggest webhosts you know, RAX, HG, etc. Being a Windows Eng in webhosting is incredibly uncommon. Prior to that and post I'm back as a bsd/linux engineer (distsys/sre now) and the Windows Server ecosystem is absolutely abysmal if you aren't in it for Exchange, MSSQL, or whatever random Windows-Only app your company uses. I supported that trash from server 2000 - 2012 r2. Never again.
- OkayPhysicist 3y agoI like PowerShell a lot more than bash, but it's got so much weird jank. String escaping gets pathological when passing arguments to cmd, or bash, or worse, both, which happens more than you'd think (looking at you, Azure CLI), and there's no good way to pipe raw bytes around (like, say, when you want to checkout a binary file from git). There's no real need to differentiate between HashTables and Objects, but it does, and it bites you at random times. IMO, they would have been better off dropping the < and > piping operators, leaving them as | Out-File and Get-Content | and then used the arrows for less than and greater than, and used == as equal to, instead of the -lt -gt -eq nonsense.
- jborean93 3y ago> and there's no good way to pipe raw bytes around (like, say, when you want to checkout a binary file from git). Since pwsh 7.4 it can natively pipe the raw bytes between two external binaries and also when redirecting to a file. Sucks it took until then to get it but it's now there.
- wvenable 3y agoYeah this my main complaint with Powershell -- Microsoft had one opportunity to build a new shell for the ages and decided to use Bash for syntax inspiration. It could have been so much better and now we're stuck with it forever.
- fr4nkr 3y agoPowershell feels a lot like Microsoft wanted to appeal to *nix users, especially system administrators, without really understanding them, presumably because D̶a̶v̶e̶ ̶C̶u̶t̶l̶e̶r̶ ̶s̶h̶o̶t̶ ̶t̶h̶e̶m̶ ̶o̶n̶ ̶s̶i̶g̶h̶t̶ Microsoft's way of doing things was and is considerably different. As a result, it hadn't really occurred to them that much of bash's weirdness and flakiness is historical, not simply because *nix users prefer it that way. The end result was still a much better language than bash, of course, but that's a very low bar.
- spiralx 3y agoIt was actually inspired by Perl as much as Bash if you read one of the asides in the O'Reilly book written by one of PS's developers lol.
- faeriechangling 3y agoEver since Microsoft decided with Microsoft Graph that “everything is a string” and “Everything is a REST API call” PowerShell has honestly seemed dumber and dumber to me. It’s great at manipulating Win32 stuff and pretty much perfect for that task sure but it’s in a weird place now since Bash and friends were always better for simple string manipulation tasks. Backticks for line continuations was also a satanic decision, even knowing of the myriad alternatives to them in PoSH.
- nrr 3y agoI'm still holding out for a Tcl port to the CLR (StrongTcl? IronTcl? Tcl#?) for exactly this reason.
- 6c 3y agoThere is Eagle: https://eagle.to https://eagle.to (never used it, just aware of its existence)
- nrr 3y agoOh, this looks like a real gem. Thank you for making my day today.
- pjmlp 3y agoAs someone that was in a startup built on top of Tcl during the dotcom wave, I doubt Tcl is coming back as it was back in 2000.
- nrr 3y agoI like the idea of PowerShell, but my constant lamentation is that it doesn't go deep enough to be considered a true shell. Many of the things that I lean specifically on bash or ksh or cmd.exe or yori.exe for ultimately lead to breaking into C#. PowerShell makes them painful. In my mind, it competes more with Python than Bourne shell: it's a scripting language that only tenuously gives you a DSL for interacting with processes and the streams between them.
- buzzin__ 3y agoWhy is world not in the hashset? Even gptchat4 doesn't know and thinks it could be because of out-null, and i should try without it. Anyone?
- koko-blat 3y ago[flagged]
- 4rt 3y agoI'm a huge fan of powershell, especially for build scripts and other things that get complicated sometimes. Parsing XML and JSON, calling web APIs and dealing with their responses are all about as easy as they can be. The article covers all the main (minor) bugbears.
- TedHerman 3y agoI mainly use Python to work with typical shell functions and external programs. I contend that Python and other similar languages are superior to PowerShell.
- mhx1138 3y agoMicrosoft is driving fragmentation with Powershell. It doesn’t really matter if it’s better than bash or not. Bash is good enough for most use cases. Yet e.g. so many of their examples for using cloud apis are in powershell, which instantly alienates everyone who doesn’t want to commit learning a redundant tool. It expresses an arrogance and disregard for their users and makes a group of people just walk away from it. That’s totally unnecessary.
- riperoni 3y agoEither i overread it or one major quirk is totally not touched on: PowerShell is case-insensitive in as many places as possible, except file paths or the likes. You can actually call .NET methods with completely nuts casing: "asdfg".tOupPer() works. Also variable names with only different cases resolve the same, i.e. $var is the same variable as $Var. String comparison with PowerShell operators is case-insensitive and it has special operators to match case sensitivity. RegEx operators behave the same way. Using the .NET methods however conserves case-sensitivity. I enjoy using PowerShell a lot. In many of places for scripting processes (Windows server adminisitration) it has an easier entry point than Python. And handling complex objects is kind of trivial. The Windows PowerShell really shows its age by now though and I hope the new PowerShell will be included by default, too.