6 ms·
PowerShell as a scripting language is a major PITA. On one project I had to maintain a PowerShell script for provisioning. The provisioning takes 2 to 3 hours.
by petilon 5y ago
PowerShell as a scripting language is a major PITA. On one project I had to maintain a PowerShell script for provisioning. The provisioning takes 2 to 3 hours. After 2 hours the script would abruptly quit because of some syntax error. 2 hours wasted.
A lot of Microsoft plugins have PowerShell plugins. This is what makes PowerShell valuable, not some attribute of PowerShell itself.
Really what Microsoft should have done is to make those plugins available to C#. Then make C# usable for scripting purposes -- C# is as easy as most scripting languages in any case, and now with "top-level statements" you don't have to write classes. Make C# usable like Dino for TypeScript (i.e., transparent compilation). Then any syntax errors in the script can be caught ahead of time, instead of after 2 hours of running.
- tyingq 5y agoYes! It's maddening trying to get the C# Powershell integration to use, Get-VM, for example. Especially in a way where it would work on somebody's else's computer.
- Kichererbsen 5y agoPowerShell as a _shell_ language though is really cool. Yes, scripting large scripts can be cumbersome, but actually having a PowerShell prompt beats having a cmd.exe prompt any day hands down! Some of the things are not... ideal. And there's a bunch of legacy stuff in modern powershell that we could do without, but a REPL scripting language with pipe semantics is really useful on a day-to-day basis. I'm not sure C# would work as a shell language at all.
- katbyte 5y agoI could never get used to verbrosesess of powershell and even when I worked with windows would always install cygwin for bash.
- AnIdiotOnTheNet 5y agoWhy do people keep complaining about PowerShell verbosity? There are default aliases for common commands, tab completion of everything, and user-defined aliases. PowerShell is only idiomatically verbose so people can actually read it, unlike your average unix shell command.
- Someone1234 5y agoBecause they start at the conclusion and work backwards. "It isn't what I'm used to, therefore bad, now let me figure out why." After that the length of commands is an easy target, in particular if you don't know enough about it to criticize it for anything substantive.
- katbyte 5y agoIt's a shell, I don't want to write a novel to get something done. bash is a bunch of small composable binaries that chain together easily. powershell is, was? not. length of commands IS important imho for a shell as I want to be able to quickly type out what I need to do and then move on
- psd1 5y agoI can code-golf in powershell. You could too, if you tried. Powershell is based on small composable commands that are easy to chain together - as you would know if you've used it at all. Valid criticisms exist of powershell. It baffles me why Linux refuseniks trot out such easily-discounted objections. My belief is that it's a figleaf over a political position: "I will never use a Microsoft product". We're on HN; that's an acceptable position. Why bullshit?
- majkinetor 5y agoI blame everybody: https://news.ycombinator.com/item?id=29488422 https://news.ycombinator.com/item?id=29488422
- sofixa 5y ago
- Someone1234 5y agoThey have a lot of shorthands for common commands, and the verboseness is on purpose, so you can guess commands and by correct 9/10. - They have a list of standard verbs: https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7.2 https://docs.microsoft.com/en-us/powershell/scripting/develo... - Every command is verb-noun. So get-[whatever], remove-[whatever], set-[whatever] etc. Therefore, you can guess get-process would be a command as is stop-process or start-process.
- kaba0 5y agoAlso, every parameter is fuzzy-matcheable.
- kaba0 5y agoI’m sorry, maybe it’s just my experience at work where I have to use it, but I really honestly hate these bash emulations on windows. Like, I honestly don’t get the point. It will die with the stupidest errors due to mismatches between the underlying abstractions, it is slow and not even its terminal emulation is on point.
- katbyte 5y agoI can only speak to cygwin, 10ish years ago, but it worked flawlessly for me at that point.
- dev_tty01 5y ago>PowerShell prompt beats having a cmd.exe prompt any day hands down! That's not a very high bar to exceed. A glass of water seems like champagne to someone in the desert.
- kaba0 5y agoOther than familiarity, it does beat bash as well, hands-down.
- netizen-936824 5y agoI will absolutely agree here. As a heavy Linux user, I always reach for PS over cmd when I need to work on a windows system The main reason for this though, is that I can use some familiar Linux commands and I don't need to google how to list files in the current dir (PS and bash both have ls, among others)
- 13of40 5y agoWhen you run a PowerShell script, the entire thing gets loaded and parsed up front, so any syntax errors are going to happen immediately. Not saying you didn't see an error, but it probably wasn't a syntax error. (Beyond that, what language are you thinking of that doesn't stop when it hits errors in your program, and is that a good thing?)
- katbyte 5y agoCalling out to another script/dynamic powershell, or maybe is referring calling a cmdlet(is that what they were called) with the wrong arguments, goes power-shell check for that? It’s been almost a decade since I used it but I echo the sentiment. It was a difficult overly verbrose language that I avoided at all costs even going so far to install cygwin so I could use bash as a command line and scripting language
- Someone1234 5y ago> Calling out to another script/dynamic powershell, or maybe is referring calling a cmdlet(is that what they were called) with the wrong arguments, goes power-shell check for that? Can any scripting language check for that? It is beyond the scope of what an interpreter has available to it.
- runjake 5y agoI disagree with pretty much your entire comment. > PowerShell as a scripting language is a major PITA. Well, except this part. > After 2 hours the script would abruptly quit because of some syntax error. 2 hours wasted. As mentioned by another commenter, the PowerShell script is parsed up front, so it probably wasn't a syntax error. My guess is the script lacked error handling and some query or connection to a remote server failed. > A lot of Microsoft plugins have PowerShell plugins. This is what makes PowerShell valuable, not some attribute of PowerShell itself. There we go agreeing again. Although, PowerShell is effectively self-documenting, which is good for busy sysadmins. > Really what Microsoft should have done is to make those plugins available to C# A lot of them effectively are available to C#, such as System.DirectoryServices.*. In the early days of Active Directory, before PowerShell, this is how we did things. While fun for us programming nerds, it took a hell of a lot more time to write usable tools. > C# is as easy as most scripting languages in any case Hard disagree. > Make C# usable like Dino for TypeScript (i.e., transparent compilation). A more C#-like scripting language? I'm all for that, but why not just use TypeScript at that point (ala the JScript days). > Then any syntax errors in the script can be caught ahead of time, instead of after 2 hours of running. No, you run into the exact same challenges, whether it's PowerShell or C#. IMHO, while I'd rather be doing C# programming any day of the week, PowerShell is more approachable for the vast majority of Windows sysadmins out there. Additionally, due to the command... verboseness of PowerShell, it is effectively self-documenting. Edit: Snover's original Monad Manifesto paper is worth a read for his reasonings about what is now PowerShell: https://www.jsnover.com/Docs/MonadManifesto.pdf https://www.jsnover.com/Docs/MonadManifesto.pdf It might be best summarized by this partial quote: "PowerShell replaces fragile, prayer-based text parsing with pipelines of objects (structured data)"
- fartcannon 5y agoYou're implying sysadmins aren't smart enough to use C#. You shouldnt speak down to a whole group of very intelligent people like that.
- jorl17 5y agoI think the idea is more that they have less time to spend worrying about compiling or deploying C# applications.
- agumonkey 5y agonever made big system scripts but I wrote a funky mouse automation with powershell 5 and it was pleasant it's not ideal but tapping into the whole system with a coherent syntax / object network is cool and you have blocks / classes to clean up your logic you can even tap directly into .net (for some reason there's a shortcut to load and compile a god damn source code string) It seems you're comparing it to ruby or python, am I right ? because IIUC powershell was more a MS OBash for Windows (without bash eternal fingercuts)
- ducharmdev 5y agoBut you can create PowerShell cmdlets using C#. If you're doing something that would really needs compile-time checks, simply extract the logic into a C# class inheriting from Cmdlet, and use that cmdlet in your scripts as needed: https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/how-to-write-a-simple-cmdlet?view=powershell-7.2 https://docs.microsoft.com/en-us/powershell/scripting/develo...
- mjul 5y agoI always enjoyed using it in reverse: when you build a .NET app it is very easy to add a CLI by exposing .NET code as cmdlets. This gives you documentation, completions and arg parsing for free while you stay in your application language. This is super useful. Think of it as the .NET and PS equivalent of a manage.py script. I agree that PS as a language is quite unusual (e.g. how it returns results) but on the other hand it’s concept of structured data also makes it powerful in ways that old-school Windows scripting or bash are not.
- majkinetor 5y agoSo you blame bad developers for stuff ? Amazing. > The provisioning takes 2 to 3 hours. After 2 hours the script would abruptly quit because of some syntax error. 2 hours wasted Anybody who designed such thing is bad. If stuff fail after 2 hours, you should be able to repeat it in idempotent way to just continue or you skip sections with parameters. Your syntax error problem is the same in any other shell, and in all dynamic languages. > A lot of Microsoft plugins have PowerShell plugins. This is what makes PowerShell valuable, not some attribute of PowerShell itself. Nonsense. I almost never use any of the "plugins". PowerShell on its own is game changer. Like the first dude already said, I have yet to see a problem that can't be done in 2-5 lines of code that is joy to read even in shorthand form, unlike countless magic chars, something that is known to be bad pattern in OOP. > Really what Microsoft should have done is to make those plugins available to C#. That is really NOT what Microsoft should have done instead of PowerShell, maybe alongside it. But since you have PowerShell, you don't need it that much. Besides, it already exists for almost decade. > Then any syntax errors in the script can be caught ahead of time, instead of after 2 hours of running. You can do this today.