by petilon · 4y ago · 0 comments
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.
> 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
It might be best summarized by this partial quote: "PowerShell replaces fragile, prayer-based text parsing with pipelines of objects (structured data)"
Oh no it isn't. Very basic stuff like Get-Something piped into a Remove-Something is, but beyond that, it gets complex quick. Add aliases, weird logic and limitations ( do you know you can't break out of a Foreach-Object?), and it quickly becomes an illegible mess that needs parsing, the same way Python might.
Furthermore, a lot depends on the cmdlet provider, and for instance the VMware ones are steaming piles of horseshit with inconsistent naming of parameters, broken async, and useless error management ( e.g. you get an error which says to check the inner exception, but it's empty and there's no way to get any detail whatsoever).
And I say that as someone who really doesn’t like windows (and thinks it is not fit for development at all) — but powershell is really a gem, if one gets over the at first strange syntax and actually looks into it.
I don't because you can.
> Furthermore, a lot depends on the cmdlet provider,
WTF, bash is unusable unless grep, sed, awk and friends are present .
No one is calling bash self documenting, so that comparison doesn't mean anything.
>A lot of them effectively are available to C#
True, though some of them aren't. I ran into one recently...setting the metric value for an ip interface (not a route, an interface). Powershell has that, C# does not, in any way that I can find.
It can be done in C# via WMI (System.Management), but that's a strange old world if you're not used to it. But it's more convenient in Powershell because MS provide modules such as NetTCPIP so you don't need to touch WMI directly.
You shouldnt speak down to a whole group of very intelligent people like that.
There’s very few times that I need to write a Powershell script that runs like a daemon. I’m typically using it in a notebook in VSCode, but I
do* have Kubernetes jobs that are written in Powershell that run periodically. They were quick and effortless to write, run fast (dotnet core,) and are easy for my team to understand if they want to modify them or someone needs to maintain them.None of my team would willingly learn C#, nor would the business support them writing C#. A powershell script though? Fair game for anyone who wants to look at something new and innovative, it requires nothing if they use ISE, and if they want to, VSCode is already an approved app. Need a hosting platform? You can deploy on Kubernetes if you really want.
It’s a really big barrier to entry to force someone to use C#.
1. Aren't "very intelligent".
2. Aren't smart enough to learn C#, let alone well enough to do systems programming to replace PowerShell.
3. Don't have the time/desire to learn C#, even if they are capable.
4. Don't have the time to write systems management code in C#, as opposed to PowerShell.
Back when I started UNIX system administration, pretty much all sysadmins knew C and could write arbitrary system management utilities in C.
This is no longer the case, for better or worse, the world needs more sysadmins and Microsoft has released server software that can be managed by relatively minimally-skilled people who know how to Google and copy/paste code from websites.
IE, the vast majority of SYS admins aren't capable of approaching C#. Fully unsubstantiated heresay. If they can learn the cryptic nightmare that is power shell, they can certainly learn C#.
Can any scripting language check for that? It is beyond the scope of what an interpreter has available to it.
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.
"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.
That said, tab completion works, and I used PowerShell on macOS for a long time with no complaints.
for scripting I'd personally use neither.
- They have a list of standard verbs: 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.
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)
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.
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)
> 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.
https://docs.microsoft.com/en-us/powershell/scripting/develo...