5 ms·
Windows has PowerShell these days, and it is actually usable and not at all awful (if a little quirky) compared to bat files.
by Kwpolska 4y ago
Windows has PowerShell these days, and it is actually usable and not at all awful (if a little quirky) compared to bat files.
- 2devnull 4y ago“Powershell(tm): Not Entirely Awful (if a little quirky)!” Seems worth investing a lot time into given Microsoft’s history of not rug pulling developers.
- connicpu 4y agoThe first release was 16 years ago and they're still making new releases of it so I'd say it's definitely here to stay ;)
- WorldMaker 4y agoAlso it is MIT-licensed open source today: https://github.com/PowerShell/PowerShell https://github.com/PowerShell/PowerShell
- thrixton 4y agoAnd cross platform: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.3 https://learn.microsoft.com/en-us/powershell/scripting/insta... Not that it’s a particularly compelling feature on Linux with the standard offering, but it’s a good option for cross platform scripts at times, particularly running in docker.
- MereInterest 4y agoI mean, if I want something that can run on as many platforms as possible without a prior installation, I stick as closely as I can to posix sh. If I want something more flexible that can run consistently, but may require an installation beforehand, I use python. I don’t really see what niche PowerShell would fill for me.
- WorldMaker 4y agoIt doesn't have to fill a niche for you. Before cross-platform PowerShell I certainly used Python for some of those kinds of scripts. I think a lot of it gets down to ergonomics/aesthetics to decide if you find a useful niche for PowerShell for yourself. Python's os module is powerful and lets you run/chain almost any native commands and shell operations you want to spawn, but it is still a very different API and abstraction with different ergonomics and aesthetics than shell-style pipes and redirects. PowerShell gives you that focus on shell-like pipes/redirects, but then gives you some Python-like power on top of that to also work with the outputs of some commands as objects in a scripting environment. There's a lot of interesting value to comparing/contrasting PowerShell and Python and if you are happy with Python maybe there isn't a big reason to learn PowerShell. PowerShell is there for when you are doing a lot of shell-like processing pipelines and want to write them as such, but have some of that power of a language like Python behind it. It's a lot more powerful than posix sh and it is similarly but differently powerful to Python but it starts from a REPL that looks/acts more like posix sh. I don't know if you have a need for that niche yourself, but I find it useful for that.
- _a_a_a_ 4y agoA bit like finding in favour of london's old, awful slums by comparing them to the Somme. "Well yes, kind of..."
- levidos 4y agoPowerShell is an absolutely amazing scripting language; it gets things done way quicker than Bash, because it's object oriented, and you don't have to call external tools to get anything done (sed, grep, find, touch, curl, etc.). It can even run raw C# code for you.
- xp84 4y agoThis definitely falls into the category for me of "things that I wasn't there for." Because I learned computers when DOS was a thing, I will always be able to write a .bat or use CMD when necessary, but having been on the UNIX/Linux side since 2003, I didn't learn C# or PowerShell but rather bash, php, ruby. So while I'm friendly with modern Windows now that they closed up the "is it a stable OS" gap with Apple, I don't really know what to do in PowerShell and am more likely to use WSL!
- WorldMaker 4y agoIt's worth learning at any age, especially now that it is an open-source, cross-platform shell. The PS Koans [1] that recently showed up on HN seemed an interesting way to try to learn it. [1] https://github.com/vexx32/PSKoans https://github.com/vexx32/PSKoans
- pjmlp 4y agoPowerShell is the closest of Xerox PARC REPL experience that ships in the box on modern platforms. Because not only it is a proper programming language, it is integrated into .NET, COM/DLLs as well, so not only you can script the OS, any application automation library is exposed as well. Nowadays, it is possible to automate anything on Windows via PowerShell, the same OS APIs exposed by GUIs are also accessible to PowerShell. On UNIX side there are things like Fish shell that also offer these capabilities, but they aren't widely adopted as PowerShell on Windows.
- tremon 4y agoSorry, but Powershell is not a programming language. It has way too many quirks and gotchas to qualify as a programming language. It is an interactive scripting language first, and a scripted language second. But a programming language it is not. To give just one example: its automatic boxing and unboxing of arrays disqualifies it as a programming language. Try to return a one-element array from a Powershell function and you'll see what I mean.
- maccard 4y agoPowershells biggest problem is error handling. There's just no equivalent to set -euo pipefail It ends up with manual error handling to handle the case of bat, ps1 and exe's
- WorldMaker 4y ago`$ErrorActionPreference = "Stop"` is very similar and does that for all of PS1 cmdlets. You still have to check $LastExitCode manually for BAT/EXEs, though. `$PSNativeCommandUseErrorActionPreference = $true` is an experimental flag [1] as of PowerShell 7.3 that applies the same $ErrorActionPreference to BAT/EXEs (native commands), stopping (if $ErrorActionPreference is "Stop") on any write to stderr or any non-zero return value. [1] https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.3#psnativecommanduseerroractionpreference https://learn.microsoft.com/en-us/powershell/module/microsof...
- arka2147483647 4y agoSadly, the powershell windows ships with is 5.1. Why? Because of backwards Compatibilytytytyy
- WorldMaker 4y ago`winget install Microsoft.PowerShell` 5.1 was the last "Windows-specific"/"Windows-only" PowerShell (and is still branded "Windows PowerShell" more than "PowerShell") before it went full cross-platform (and open source). It's an easy install for PowerShell 7+ and absolutely worth installing. If you are using tools like the modern Windows Terminal and VS Code they automatically pick up PowerShell 7+ installations (and switch to them as default over the bundled "Windows PowerShell"), so the above command line really is the one and only step.
- pxc 4y agoYou can also install the latest PowerShell Core (the open-source, cross-platform releases we're talking about) via Scoop, which is a package manager for Windows that works even if you don't have admin rights: https://scoop.sh/#/apps?q=pwsh&s=0&d=1&o=true https://scoop.sh/#/apps?q=pwsh&s=0&d=1&o=true
- blibble 4y agopowershell is still built on crap I had it randomly throwing exceptions the other day that a path was too long (it was only about 300 characters...)
- mdaniel 4y agoThe irony of commenting that under an article that cites the maximum path cannot exceed 260 characters is not lost on me
- blibble 4y agohow is that ironic?
- inferiorhuman 4y agoIt's like rain on your wedding day
- noAnswer 4y agoBut the path length can be longer! They just don't care and offload the work.
- mauvehaus 4y agoThe maximum path length of the NT kernel is 3276-something UCS-2 characters. 260 is a limit imposed by the legacy Win32 interfaces IIRC. I believe the W-interfaces get you the full-fat version, it's just that they're so inconsistently used as to all but guarantee that something you need will have problems. The user-mode stuff is kind of a mess. The kernel-mode stuff is comparatively orthogonal.
- magicalhippo 4y agoYou also have to prefix[1] the path with \\?\ unless you've enabled a group policy[2] in Windows 10+. [1]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#parameters https://learn.microsoft.com/en-us/windows/win32/api/fileapi/... [2]: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation https://learn.microsoft.com/en-us/windows/win32/fileio/namin...