30 ms·
> powershell's principle is based on the principle of most surprise. I don't think that's true at all. Compare powershell command names to UNIX command names f
by AnIdiotOnTheNet 8y ago
> powershell's principle is based on the principle of most surprise.
I don't think that's true at all. Compare powershell command names to UNIX command names for example. You can rest assured that Get-X will not change things and that there is almost certainly a Set-X that will, for example. You can tab complete variable names, cmdlet names, cmdlet switches, etc. Additionally, by piping objects instead of text, you aren't caught off guard by things like spaces in a path name.
> Like when I tell it to download something, I don't expect to have to futz with IE browser settings (WTF?!?!).
It definitely does have some flaws though, I'll give you that.
As an aside, you can use Invoke-WebRequest with the `-UseBasicParsing` switch to leave IE out of it. They definitely should have done that the other way around.
- setquk 8y agoThe last point is the point really. The entire objectivity of it is ruined by weird edge cases and knowledge. The car only goes straight if both rear windows are open. You have to say "beetlejuice" three times before putting it in reverse etc etc.
- AnIdiotOnTheNet 8y agoYou sure you aren't describing an average UNIX command?
- setquk 8y agoNo because you don't have to google for an hour to find the "don't punch me in the dick" flag.
- AnIdiotOnTheNet 8y agoInstead you just have to google how to use `tar` properly. Again. You can tab complete powershell cmdlet switches. And MSDN has extensive and good documentation. Here's the page for Invoke-WebRequest. Notice the very first switch listed. Further note that Microsoft realized they screwed this up and deprecated the switch in PS 6.0 since it is now the default. https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-6 https://docs.microsoft.com/en-us/powershell/module/microsoft...
- setquk 8y agoNo googling because it hasn't changed in the last 20 years. How do you unzip a 20 gig file in powershell? 1. You can use the windows shell via complicated series of calls. This runs like ass as the windows built in decompression is terrible. Also it only works properly if there's a desktop session running so over WinRM it does with a COM error. 2. Find out which version of powershell you have, hope it's 5.0 or later or install the right WMF version and then run expand-archive. And it still runs like ass. But oh no we can't because now we have to push WMF 5.0 to 150 servers which is going to take DAYS with SCCM. Some kit is on Windows 2012, some on 2012 R2 and some on 2016 because it's so damn hard migrating stuff as it has to be done by hand so you have a mix of stuff leading to a nightmare from hell. 3. Import System.IO.Compression and call .Net to do it then wrap it in a cmdlet called Expand-Archive, then wonder why it breaks when someone pushes out WMF 5.0+ 4. Push 7za.exe out with ansible and run that. This is the problem. No good outcome for really simple tasks. Friction for all of them. Edit: I'm being 100% honest here and say I hate it with such a passion because I've lived in the same building as it for several years, not because I'm not aware of how it works.
- AnIdiotOnTheNet 8y ago> Import System.IO.Compression and call .Net to do it. ...and? Why is that a problem? It is an advantage that PowerShell can call on the CLR directly (including its C FFI).
- setquk 8y agoBecause half the time it slings Exception calling "ExtractToDirectory" with "2" argument(s): "End of Central Directory record could not be found." 7zip works fine! (copied straight from my MASSIVE OneNote book of weird powershell and .Net errors and workarounds). Also they just deprecated OneNote desktop other than the turdy UWP app. Another thing to be angry about.
- AnIdiotOnTheNet 8y agoBut you're completely willing to forgive UNIX's toolset's problems because you're used to them after working with them for decades. I get it, but that does not make them better.
- laumars 8y ago> You can tab complete variable names, cmdlet names, cmdlet switches, etc. UNIX shells can do all that too. > Additionally, by piping objects instead of text, you aren't caught off guard by things like spaces in a path name. Not just spaces, to be fair. Files that begin with a hyphen can cause major issues too. There’s definitely a lot of weird edge cases with UNIX shells but on the whole I still find them easier to work with than Powershell. But that’s just me
- twothumbsup 8y agoWhich one did you learn to use first? Wondering if that has much of an impact. I've only used Powershell for a bit while I work with *nix shells daily so I'm definitely biased towards them but wonder if I'd cut my teeth on Powershell if I'd think the same way.
- laumars 8y agoNeither. I leaned the CLI from DOS (or it might have been CP/M?). Unless you count BBC BASIC?
- pjmlp 8y agoWhat about UNIX shells that allow to call public functions in dynamic libraries as if they were shell commands? Or interact with running applications using the OS APIs like Powershell allows with WMI, COM, OLE Automation and .NET? Yes, there is DBUS, but isn't really integrated across the whole stack.
- laumars 8y agoIf I want that level of control I wouldn’t want to be writing a shell script in the first place. That’s the problem with Powershell for me, it’s taken the REPL concept but made it too feature rich and too verbose so you lose the speed of writing the code and simplicity of piping predictable streams of data. The thing with Linux / UNIX is it’s very command line driven from the outset. So if you wanted to do the function calls from shared libraries et al you could write a wrapper in C, Python, Perl, whatever and still use Bash etc to interface with it. You’re not tied to using Bash to solve all of your problems. Bash just provides a convenient interface for chaining all those tools in other languages together. Now I know the same can be said for command prompts on Windows but for whatever reason that seems to be less common than it is on POSIX.
- Someone1234 8y ago> As an aside, you can use Invoke-WebRequest with the `-UseBasicParsing` switch to leave IE out of it. They definitely should have done that the other way around. They have made that change: > This parameter has been deprecated. Beginning with PowerShell 6.0.0, all Web requests use basic parsing only. This parameter is included for backwards compatibility only and any use of it will have no effect on the operation of the cmdlet. 6.0.0 was released on 10 January 2018.
- discreditable 8y agoFun thing about Invoke-WebRequest is that it uses TLS1.0 by default and doesn't understand anything newer unless you enter an incantation beforehand: [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
- setquk 8y agoIt’s even worse thatn that as the behaviour is defined by a weird combination of the OS, the .net framework, powershell version and local policy settings.
- discreditable 8y agoYes, I imagine a lot of .NET devs don't realize their apps are TLSv1.0 only. I've worked with one vendor who was surprised when I told them.
- setquk 8y agoExactly that. Some vendors have only just got rid of SSLv3 in financial services as well. It’s slightly scary.
- slavik81 8y agoI was teaching a class on algorithms to some engineering students. They needed to sort a file of random integers using a few different algorithms. This is the bash I wrote to check their results were sorted properly on Linux: diff <(cat output.txt) <(cat input.txt | sort -n) This is the PowerShell I wrote to check their results were sorted properly on Windows: cat input.txt | foreach-object { [Int] $_ } | sort-object | out-file -encoding ascii sorted.txt diff (cat output.txt) (cat sorted.txt) The casting felt a little painful, but it seemed straightforward. The sorted result was generated correctly. Unfortunately, I was surprised to discover that PowerShell's diff found no differences between a sorted file of numbers and the unsorted file of numbers.
- AnIdiotOnTheNet 8y agoThat's because `diff` is an alias of `Compare-Object`, which works radically differently than UNIX `diff` because of the defaults. In some circumstances you could see how this behavior would be more useful, though obviously not this one. For reference, `Compare-Object -SyncWindow 0` would give the behavior you wanted. The default is [Int32]::MaxValue. Aliasing UNIX command names is another one of PowerShell's mistakes in my opinion, because it creates the expectation that they work the same way when they often very much don't. Ultimately rather than help UNIX users, as was probably intended, this just confuses and annoys them.
- yjftsjthsd-h 8y ago> rather than help UNIX users, as was probably intended, this just confuses and annoys them. Compatibility layers are great, when they're actually compatible. Almost-compatible layers are a nightmare.
- wolfgke 8y ago> Compatibility layers are great, when they're actually compatible. Almost-compatible layers are a nightmare. That's why you should not use them. You decided to use them.