back to article Welcome, stranger: Inside Microsoft's command line shell

PowerShell is everywhere, it seems. Not just in Windows Server, SharePoint, SQL Server, Exchange, Lync and Azure cloud, but it’s in third-party software, too. Take VMWare PowerCLI – that’s an extension of PowerShell. With many in the Windows world chewing on this fat PowerShell server software sandwich it’s easy to take …

Page:

    1. AdamFowler_IT

      How is "dir c:\*.* /s | more" the same as "So get-childitem | where name -notlike Windows" - yours will stop at each page waiting for a keypress, mine lists everything excluding the directory name 'Windows' ?

  1. Anonymous Coward
    Anonymous Coward

    Obscure knowledge got me a job ....

    1996 - for various reasons been out of IT for a few years. Had to start low, so applied for a support job. Technical Director asked me:

    "Imagine you haven't got a text editor. How would you create a file."

    I guessed he was expecting echo "This text">C:\FILE.TXT. What I said was "I'd use the DEBUG command to write to a text file.".

    Turns out he'd not heard of that one, and he said so. MD heard him and hired me.

    1. Anonymous Coward
      Anonymous Coward

      Re: Obscure knowledge got me a job ....

      Or you could just use EDIT.

      I guess for some people proving they know something abstract is more important than the simple answer.

      1. Anonymous Coward
        Anonymous Coward

        Re: Obscure knowledge got me a job ....

        Erm, the constraint was "you haven't got a text editor"

        1. Tom 13

          Re: the constraint was "you haven't got a text editor"

          I would have opted for Edlin. Nobody who has ever used it has ever confused it with a text editor.

          1. david 12 Bronze badge

            Re: the constraint was "you haven't got a text editor"

            Edlin was a Line Editor. Which was still a well-known kind of thing in the world when PC DOS was first introduced.

      2. Dave 126 Silver badge

        Re: Obscure knowledge got me a job ....

        copy con reply.txt

        Of course you could also do this

        And when you had finished, you would

        Ctrl-Z

        1. Ol'Peculier
          Unhappy

          Re: Obscure knowledge got me a job ....

          Glad I wasn't the only one that thought of that solution.

          Grief. I feel old...

        2. omnicent

          Re: Obscure knowledge got me a job ....

          Damn, I wanted to add the "copy con" command, that was my fav....

          1. david 12 Bronze badge

            Re: Obscure knowledge got me a job ....

            Real programmers use

            copy con program.exe

          2. Anonymous Coward
            Anonymous Coward

            Re: Obscure knowledge got me a job ....

            Hell, copy con wasn't my favorite DOS command, but it was the first one ever shown to me.

            It was only 30 years ago, but this article makes it feel like yesterday, I feel more stuff dripping out of my UMB with every comment. Thanks for taking us all back, Adam.

            1. AndrueC Silver badge
              Boffin

              Re: Obscure knowledge got me a job ....

              My memory actually goes back a little further than copy con...

              pip test.txt=con:

              :D

        3. AndrueC Silver badge
          Boffin

          Re: Obscure knowledge got me a job ....

          And when you had finished, you would

          Ctrl-Z

          Nah. I'd hit F6 instead :)

      3. HipposRule

        Re: Obscure knowledge got me a job ....

        Edlin surely, didn't edit only come in with DOS 5?

        1. Colin Miller

          Re: Obscure knowledge got me a job ....

          Edlin was in MS-DOS 3.1

    2. Anonymous Coward
      Anonymous Coward

      Re: Obscure knowledge got me a job ....

      Ah, con, aux prn, still lurk in today's cmd line.

      copy con "file.txt" (CTRL-Z)

      Not so long ago a test program I was using, designed to test file system security permissions, would occasionally randomly break, for no apparent reason. The youngish chap who wrote it was randomly generating file names. After digging through a lot of tracing, every now and then, the random file name generator was attempting to create files called "con", "aux" and "prn", creating a big spanner where none was expected.

      Just occasionally old arcane knowledge comes in handy.

      1. Pirate Dave
        Pirate

        Re: Obscure knowledge got me a job ....

        Ehhh, I still use copy con when I'm creating small test files. Old habits die hard.

        And actually, on several of my 2012 servers, I use batch files for backup jobs (along with an rsync client). Easier, more comprehensible that Powershell, IMHO. And more straight-forward. Put too many powershell one-liners in a script, and a year later I'm like "what the fuck did I do here?" Only time that happens in a batch file is if I try to get really fancy with a FOR command.

        Powershell has some uses, although after 4 years of using it, I really think it's main strengths are dealing with "new" Windows or Office365 features that are Powershell enabled. For stuff like that (especially dealing with O365, and to a lesser extent, AD), some of it is much, much easier to do in Powershell than in a GU, webpage, or a batch file. But many times it's easier to do something using a simple batch file and an executable utility rather than try to figure out the arcanum to invoke it in Powershell (or worse, have to drop to the underlying .NET stuff).

        And the key to keeping your sanity is to remember Powershell is a SCRIPTING language, not a PROGRAMMING language, even though MS tried really, really hard to make it look like programming.

        1. John 104

          Re: Obscure knowledge got me a job ....

          The trick to remembering "what the fuck did I do here" is to write comments in your script so you don't have to remember in 6 months...

          And in case you don't know how to do that....

          #

          Personally, I've been using it since inception and it is hands down better than the endeared dos command line. And it blows the shit out of VBS.

          Stay current, learn new tools, stay employed...

          1. Pirate Dave
            Pirate

            Re: Obscure knowledge got me a job ....

            To each his own, I guess.

            I never cared for VB script. For places where I could have used it, I'd usually go into VB6 instead. Always seemed easier to just copy an EXE around to various machines than deal with the scripting engines.

        2. Adam 1 Silver badge

          Re: Obscure knowledge got me a job ....

          >Only time that happens in a batch file is if I try to get really fancy with a FOR command.

          Or any other processing involving the system date; stuff like rename that zip file with the prefix 20150428 is a right PITA with batch files.

          1. Pirate Dave
            Pirate

            Re: Obscure knowledge got me a job ....

            "stuff like rename that zip file with the prefix 20150428 is a right PITA with batch files."

            Yes, but the newer versions of the SET command can do that kind of stuff fairly easily (for some values of "easily"), it's just dog-ugly syntax and a real "WTF?" moment a year or two later without comments explaining it.

    3. Alan Brown Silver badge

      Re: Obscure knowledge got me a job ....

      COPY CON (which lots have beaten me to)

      And F3/F8 plus others for command line editing.

      I actually went out and bought a copy of IBM DOS 3.3 specifically because the manual which came with it came with full explanations and examples for every single command.

      The MS-DOS manuals were poor things by comparison.

      That IBM manual stayed around until the late 1990s, because it was a useful reference tome. It went walkies when shifting house and I suspect one of my "helpers" decided it was more use to him than to me.

  2. This post has been deleted by its author

    1. launcap Silver badge

      Re: paths

      >> “Bad command or file name” message

      >To be fair, that's true in *n*x shells as well.

      However - most *n*x shells are not set up (unless the sysadmin is *really* clueless) with . as one of the PATH entries..

      1. Alan Brown Silver badge

        Re: paths

        Even most clueless unix sysadmins generally set "." as the _last_ PATH entry.

        With DOS it was the first one, which made trojan horsing much easier

        I had to deal with a number of infestations caused by that and the old BIOS flaw of looking at the floppy before trying to boot off HDD. Every single computer I worked on that could have the boot order changed, did so (often to the consternation of "experts" who would advise users not to boot with floppies in, and then have their demonstrations fail)

        1. AndrueC Silver badge
          Meh

          Re: paths

          With DOS it was the first one, which made trojan horsing much easier

          True and arguably it's even worse than that. That's because command.com always looks in the current directory and only resorts to PATH after checking the cwd. So even if your PATH variable is empty you'll still execute programs in the cwd. I'm pretty sure there is no way to stop command.com looking in the cwd first but I vaguely recall that with 4DOS at least if PATH did contain '.' then it overrode the default behaviour and thus at least allowed you to push it further down the list.

          1. david 12 Bronze badge

            Re: paths

            Yes, PCDOS 1.x was primarily a floppy disk system, and it always ran programs off the current floppy disk, and did not require a path to do so. When it morphed into something completely different, this started to be a problem.

            no, it did not require a path, and dot was never an element of the path. It did become common to put things like root or dot dot into the path, and the order of the path was commonly set for optimum speed, because, until very late in the piece, MSDOS did not cache the file listing, and even on Hard Disks, a path search could be noticeably slow.

        2. tom dial Silver badge

          Re: paths

          Not US DoD administrators, and never, ever, for those with privilege.

  3. boltar Silver badge

    Piping and conditional logic

    Thats where command lines excel. GUIs are great for single tasks that can be visualised - eg drag and drop or button clicking - but for disperate non visual or abstract tasks that need to be linked together and require some glue logic and maybe looping , well , some GUIs have been designed that can do that (Scratch programming language for example) but its easier just to use an old fashioned command line whether its powershell on windows or bash on linux.

    1. phuzz Silver badge

      Re: Piping and conditional logic

      To use the example of Exchange, if you have to check that pager number for a particular employee is correct, you're probably better off using a GUI.

      If you have to change the pager number for a whole group of people then the command line is a better choice.

      Your level of comfort with a command line could be quantified by how many times you're willing to repeat a manual task before busting out a batch file to automate it.

      (Note to kids: a pager was a sort of proto-smart watch that you wore on your belt rather than your wrist, but it had it's own radio so you didn't require a phone)

      1. John 104

        Re: Piping and conditional logic

        (Note to kids: a pager was a sort of proto-smart watch that you wore on your belt rather than your wrist, but it had it's own radio so you didn't require a phone)

        Wins the internet for the day.

    2. Jim 59

      Re: Piping and conditional logic

      Big up the command line in general. For many of us, it was also a natural progression from the 1980s home computer usage.

    3. Alan Brown Silver badge

      Re: Piping and conditional logic

      "GUIs are great for single tasks that can be visualised - eg drag and drop"

      If you've ever seen what goes on behind the scenes with "drag and drop" you'd run screaming.

      Multiselect (Unixen, Macs and Windows alike) results in a series of INDIVIDUAL commands. I've seen many systems brought to their knees by that kind of shitty behaviour (particularly if the target directory is on a network fileserver)

    4. Adam 1 Silver badge

      Re: Piping and conditional logic

      Many ps applications basically generate the appropriate cmdlet that achieves what you clicked. This lets you do it through the ui, then grab the script and do it in bulk.

  4. Extra spicey vindaloo

    "Commands and paths had to be typed in full in the MS-DOS days, there was no fancy time-saving command-line auto completion. This feature popped up much later in the picture, when the command prompt had almost become a forgotten artifact of the pre-GUI era."

    DOSKEY was available from MSDOS 5.0 and later.

    Powershell is powerful but, I use it maybe once a month, and then mostly for Chocolatey.

    But I have a command window open on my machine nearly all day. At the moment there are 3 of them.

    Dir *.txt is a hell of a lot faster to find a file than trying to find it in a window.

    1. TonyJ Silver badge

      But I have a command window open on my machine nearly all day. At the moment there are 3 of them.

      Similar here, but I use a PS window. Since it does everything the a command window does, plus the PS bits, I prefer it that way.

      Each to their own. :)

      1. Pirate Dave

        One of the things I miss most frequently in PS are the switches to the DIR command.

        dir /a-d

        dir /o-g

        those are mighty handy at times. I seem to recall they can be sort of emulated with scripting in your profile, but it would have been nice if MS had added them by default.

    2. billdehaan

      DOSKEY was available from MSDOS 5.0 and later.

      And there were many other keyboard and command line enhancers before then. My personal favourite was Chris Dunford's CED (command editor) back in 1987, three years before DOS 5 came out. I liked it enough that I bought the the professional version, PCED. Sadly, it had some conflict with the Smartkey keyboard enhancer, as I recall, but by then, we were already playing with the (late, but not lamented) Command Plus shell, and later 4DOS, rendering DOSKEY moot.

      Sadly, I now have a quirky application which for unknown reasons doesn't like to run in TCC/Take Command, and so I *must* launch it from a DOS shell, forcing me to learn/relearn DOSKEY, thirty years later...

    3. david 12 Bronze badge

      Fn keys were available from DOS 1 and later. Giving you, well, very very basic command line completion.

    4. AdamFowler_IT

      You can still do that command in a PowerShell window.

  5. Len Goddard

    Discovery

    I was completely unaware of Powershell until I found it on the Win 10 Tech Preview. It is a definite step in the right direction, I suppose, but for me it won't replace the cygwin linux command line / utilities package I always install on a new system before I do anything else.

    1. Lee D Silver badge

      Re: Discovery

      I stopped using powershell the moment I realised that a simple AD command to do something (I think it was related to promotion of a certain role, but can't remember off-hand) had gone from an 8-character name to something so long and unguessable that - even with autocomplete - there were ten similarly named, stupidly long, easy to confuse commands and that in any tutorial they had to be written out correctly and not jump off the sides of the screen when you typed them because otherwise it was too easy to hit the alternates.

      That's not what you want when you're playing with AD in a Powershell box.

      1. Anonymous Coward
        Anonymous Coward

        Powershell - I knew it well

        There I was on site in Foreign lands trying to get Powershell to failover a Server 2008R2 CORE cluster.

        The problem was that the Cluster commands were not available.

        The problem was that a 'Mandatory???(Wtf)' patch had disabled/removed them.

        A OPTIONAL patch if it had been applied would have re-enabled them again. Doh!

        How many hours of head bashing resulted? Far too many.

        Onto the command language.

        It seems that the Powershell designers have taken the worst bits of DCL (Digital Command Language) from VMS and used them. After years and years of using VMS even I find the syntax frankly *******.

        1. A Non e-mouse Silver badge

          Re: Powershell - I knew it well

          It seems that the Powershell designers have taken the worst bits of DCL (Digital Command Language) from VMS...

          Windows NT was inspired by VMS due to the work of Dave Cutler who worked on VMS at Digital before moving to Microsoft to work on NT. en.wikipedia.org/wiki/Dave_Cutler

        2. Roo
          Windows

          Re: Powershell - I knew it well

          "It seems that the Powershell designers have taken the worst bits of DCL (Digital Command Language) from VMS and used them. After years and years of using VMS even I find the syntax frankly *******."

          I'm glad someone else has had that thought. I spent a couple of years using DCL, tried bourne shell and never looked back... Until I tried PowerShell, which reminded me why I didn't go back to DCL. ;)

          For the record I didn't actually mind DCL when I was using it - but then again I didn't know what I was missing until I get a couple of weeks of Bourne shell under my belt...

      2. jsnover [MSFT]

        Re: Discovery

        I always thought about the admin at 3am in the middle of an IT crisis in mind. I thought about the desperation that person would feel if they were trying to understand what had occurred and opened up a PERL script and needed to understand it. When that person opens up a PowerShell script, they will be able to read it and understand what happened.

        That is why things tend to be more verbose - because verbosity is your friend when the chips are down. As you correctly point out, verbosity is not your friend for interactive use. That is why we provide aliases, positional parameters, wildcards, etc.

        At the end of the day, we build tools to make you successful so if you are successful with the tools you are using - then it's all good.

        Jeffrey Snover [MSFT]

        Distinguished Engineer

        1. HmmmYes Silver badge

          Re: Discovery

          But why does my Powershell take several 10s of second before I can enter a command?

          Is powershell meant to be a programming environment, or an interactive one? Powershell seems to be stuck between the two.

          I trying to move all my Windows stuff to powershell and I am finding it a PITA. Its powerful, sure but a shell???

          Oh and don;t get me started on all the different versions? Did you not learn anything from WinSocks?

        2. Roo
          Windows

          Re: Discovery

          "I always thought about the admin at 3am in the middle of an IT crisis in mind. I thought about the desperation that person would feel if they were trying to understand what had occurred and opened up a PERL script and needed to understand it. When that person opens up a PowerShell script, they will be able to read it and understand what happened."

          People can write unreadable code in pretty much any language out there, and at 3AM the chances are groking anything is going to be harder than usual... So instead of forcing people to learn new tools, syntax and conventions at 3AM how about just using presenting them with something familiar & well proven - like Python packaged with a bunch of libs to facilitate doing tasks on Windows boxes ?

          I'm guessing it's down to our old friend "Not Invented Here".

    2. sawatts

      Cygwin

      - ditto -

      I tend to use Cygwin on every Windows box I have to use. While I know that some people are thrilled with PowerShell, but I use the same Bash scripts on UNIX and Windows.

      Anyone else remember that Windows NT originally came with a POSIX-subsystem?

      1. Roo
        Windows

        Re: Cygwin

        "Anyone else remember that Windows NT originally came with a POSIX-subsystem?"

        Yes, I do. I mainly remember because it wasn't actually shipped with the POSIX subsystem in working order (as of NT 3.51), you had to install it off an extra CD. The advertising was very misleading. In my experience that feature was successful at convincing mentally defective PHBs that NT could run code currently running on UNIX boxes than it was actually doing it's job...

Page:

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2019