top | item 10352230

(no title)

harkyns_castle | 10 years ago

Pleasantly surprised by powershell? I don't know what to say. I have to essentially copy and paste fragments of things that work, it's so arcane. Its like writing 90's Java on a command line. Its revolting.

Still to this day I can't even fscking grep.

discuss

order

ygra|10 years ago

> I have to essentially copy and paste fragments of things that work, it's so arcane.

I have about the same problem when it comes to bash. While bash may very well be described as "arcane" I believe this is mostly a problem of unwillingness to learn something new or different.

Understanding how PowerShell works takes a bit of time and re-thinking. It doesn't help that there's so much downright bad PowerShell code out there that was mindlessly converted from VBScript. Still, it's not that hard and the language is quite consistent and, well, powerful. They made quite a large effort to make sure that the underlying concepts are orthogonal and pervasive throughout. So learning just a few concepts actually make a very large part of the shell and language approachable and easy to understand.

tacticus|10 years ago

Why are you comparing powershell to bash. the more accurate comparison is python.

Raesan|10 years ago

When powershell comes up, someone always gripes about how they can't do this or that like they can in bash. I'm not going to deny that grep is nicer to use that the powershell equivalent (Select-String). But you don't configure Windows and other software in the Microsoft ecosystem by messing around with text. For example, if you had a new user and you wanted to set up an account, email address, and phone number (so AD, Exchange, and Lync/Skype for Business in Microsoft land), it wouldn't just be hard using something like Cygwin, it would probably be impossible. There is just no way to talk to those programs text streams or config files.

I guess what I always want to know when people complain about powershell is what they were actually trying to do. I think it's an excellent tool for system administration in a Microsoft environment. When you start moving away from that use case, it gets less and less useful.

tacticus|10 years ago

the problem with powershell is that it is incredibly stupid if you're not on a full windows stack (desktops, servers and near enough to everything inbetween) and running the most recent version of windows (ever tried getting winrm installed and reliably working on a 2008 box?)

perhaps if they were not too opposed early on to horrible open source things and just one of the languages that already fit fairly well in that area (python for example) they wouldn't have had to go out of their way to make pretty shitty hacks (i really wonder if anyone in the powershell\winrm team did any testing or development with the machines more than 10 metres away)

gecko|10 years ago

I suspect you haven't read the documentation or tried using PowerShell for any length of time. PowerShell may be bash-like, but it's not bash, does not try to be bash, and won't reward you if you treat it like bash. But it's very orthogonal, clean, and well documented.

For your particular example:

    > help grep
    
    Name                              Category  Module                    Synopsis
    ----                              --------  ------                    --------
    Out-File                          Cmdlet    Microsoft.PowerShell.U... Sends output to a file.
    Select-String                     Cmdlet    Microsoft.PowerShell.U... Finds text in strings and files.
Okay, so Select-String sounds really promising. Let's take a look.

    > help select-string

    NAME
        Select-String

    SYNOPSIS
        Finds text in strings and files.


    SYNTAX
        Select-String [-Pattern] <String[]> [-Path] <String[]> [-AllMatches] [-CaseSensitive] [-Context
        [<Int32[]>]] [-Encoding {unicode | utf7 | utf8 | utf32 | ascii | bigendianunicode | default | oem}]
        [-Exclude [<String[]>]] [-Include [<String[]>]] [-InformationAction {SilentlyContinue | Stop | Continue |
        Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-List] [-NotMatch] [-Quiet]
        [-SimpleMatch] [<CommonParameters>]
Most of those command flags seem really straightfoward to me. Can you be more specific about what was unclear to you? I'd be happy to help.

EDIT: BTW, it's a bit annoying to type Select-String, so it'd be nice if it had an alias. Does it have one?

Well, you can get aliases in PowerShell by typing alias. But that'll give you a wall of text; what you want to do is to quickly search for things that are aliased to Select-String.

There are two ways to do this. First, you can pipe to a GUI that allows directly filtering the results:

    > alias | out-gridview
Or, alternatively, we can figure out what objects alias gives us:

    > alias | select -first 1 | get-member
Note that we've got a Definition field, and query on that:

    > alias | Where-Object { $_.definition -contains 'Select' }
which is a long version of

    > alias | ? { $_.definition -contains 'Select' }
And notice that Select-String is aliased to sls by default. Note that I can just reference the column by name, rather than going through some awk/cut fun.

You might be annoyed that Select-String is not aliased to grep. While many commands actually do have multiple aliases to both DOS and Unix equivalents (e.g., Get-ChildItem is aliased to gci, dir, and ls, and Remove-Item has ri, rm, and del as aliases), Select-String works differently enough from grep that it's not a default alias so you're not confused.

harkyns_castle|10 years ago

Fair enough, and I have and will continue to not really want to invest time into learning Microsoft's stuff, based on past experiences (my first being wanting to develop for the platform as a scrub, and they charged thousands of dollars for a dev environment/compiler). I honestly don't think it'll serve me well going forward, when there are better alternatives.

They have had decades now to get on board with developers, and cmd.exe is still their go-to console. They still strike me as a company of greedy corporate business folk, who happen to run a software company, as opposed to a software company that has to suffer greedy corporate drones to survive in our current race to the bottom.

pjc50|10 years ago

Select-String works differently enough from grep

Correct - it has a couple of crippling features, such as wrapping output at 80 characters even if piped to a file (unless you tell it otherwise every time).