2 ms·
> Powershell's syntax is so fucking weird and verbose. You're not wrong. I think it's that way because of trying to increase readability. Best practice for P
by RajT88 3y ago
> Powershell's syntax is so fucking weird and verbose.
You're not wrong. I think it's that way because of trying to increase readability. Best practice for Powershell cmdlet development is verb-noun.
Of course they throw that out the window with aliases.
Examples:
wget and curl both are aliases for invoke-webrequest
iex is an alias for "invoke-expression" - which lets you execute a string as powershell code in your same session (note: I originally wrote scriptblock, which was incorrect - otherwise something I wrote this week wouldn't work at all, due to change of scope). This ability gets me out of a lot of weird jams.
The other thing too which makes it so weird is that it is built on top of .Net. The overarching principle of Powershell is that it's your Windows swiss army knife. You can access .Net classes by loading the assemblies. I have on occasion built a small WinForms app in powershell. You can create and invoke COM objects (new-object cmdlet).
> But as a polyglot I am so sick of having to learn yet another syntax.
Personally, I try to avoid "language specific sugar" when I am writing sample scripts for people (I am in a customer facing role). But goddamn I love the shorthand way you can do a for loop in Powershell using the range operator:
1..100 | % {Write-Host $_}
> cmd.exe does everything I need to and batch is actually kind of flexible.
OK, so you haven't really gotten to know Powershell very well if you're saying things like this. lol
Scripting in batch files is like living in the dark ages. They are "kind of flexible" whereas Powershell is "very flexible, most of the time".
And that "most of the time" caveat is no longer there if you are on the latest powershell (which doesn't work with the ISE as ISE is 5.x only, and the way of the future is the universal PWSH). My biggest gripe was fixed I think in Powershell 7, which was manipulating files with grave marks in the name.
I build a lot of stuff in Powershell, as you can probably tell. Given all the interop stuff it has, once you know how to use it all, the point where it makes sense to build it in C# is farther down the line than you might think.