Tuesday, May 30, 2017

Coming to Grips with Microsoft Powershell

The following article contains segments of sarcasm and defeatism. It is simple venting and not helpful in any way and should be ignored by the general population.

PowerShell from a Beginner's Perspective

So, with all the downtime I've had lately (being unemployed) I decided to take some online classes to answer some of the questions I've had about many of the products I use, and to alleviate the boredom... Okay, so it's mostly to alleviate the boredom, but it never hurts to learn a new skill.

Since my unemployment wages aren't exactly stellar, I really don't have the resources to pay for an actual class with an instructor and credit. Luckily, most of the courses in the Microsoft Virtual Academy are free. I've used PowerShell in the past, but never really understood what it actually was, mistaking it for a fancy command line terminal. It was with great enthusiasm that I found a PowerShell course for beginners on the MVA site. That's where the trouble began...

I'm no stranger to DOS, and its derivative, the Windows command line. I've used various Linux builds in the past, but I would be lying if I said I really understood the whole terminal system, which is its core. I've also used Unix once or twice, but only to type in the commands that I was told to type in, and never to learn how to use it effectively. I thought I'd bite the bullet and try to learn something productive and useful.

Let's get down to it.

PowerShell is a non-graphical program. It looks like white text on a blue background. There are no buttons to click, and no pictures to look at. It was made (I suspect) to look like a Unix terminal program. It is simply the most boring-looking program you'll use this side of Notepad.

At first, DOS and Windows Command Line people will think that it's just a fancy and more powerful command line system, and they're kind of right... Let's say (for example) that you want to list a directory in PowerShell. In DOS, you would type the command "dir" to bring up a list of files and programs in the current directory. In PowerShell, you could also type "dir" to do the exact same thing.

Well, not exactly the same thing... You see, PowerShell is quite a different animal on the back-end. Unlike DOS (which is essentially just a text parser), PowerShell is running these programs and commands in real-time. The reason you can type DOS commands and get the same results is because they use an "alias" system to assign common command line instructions from DOS, Linux, and Unix to link to similar commands in PowerShell.

For a list of aliases in your PowerShell program, type "alias" and hit enter.

While these aliases do a pretty good job of letting you do basic stuff with little experience, the problem is that some of the more involved parameters of the commands are absent. For example, typing "dir /p", which in DOS would display the directory contents one page at a time instead of all at once, will not work and return an error message.

The 10 (thousand) Command-lets

PowerShell uses a system of commands known as cmdlets (pronounced "command-lets") to perform operations. They are put together in a verb-noun syntax. If you wanted to get a list of the cmdlets available to you, for example, you would type "Get-Command" and PowerShell will inundate you with far too many commands to register in your feeble meat-brain. Each of these commands will also have a number of parameters (some of which are required) that don't show up in the list, making the program all but useless.

"But it's okay," the PowerShell developers scream, "Because we have a robust help system!" And they're not lying: There IS a robust help system. How does it work? It's simple: 

All you have to do is know exactly which of the hundreds of cmdlets you need ahead of time, and simply type "help (cmdlet nem here)" for a huge page of information (all poorly-formatted text) that tells you way too much information about the command that you want, thus confusing you further.

(Editor's note: You also have to download the help files using a special command. I forgot what it was. Good luck finding it!)

You know what's even better? Depending on what system you're on and what PowerShell packages they've installed, you could have THOUSANDS of cmdlets to dig through. Bon appetit.

So basically, the procedure is this: Go online via your web browser, spend an hour looking for the right command for what you want to do, type it in, and then wait for the error message to pop up.

What? Errors?

Yes, because every cmdlet has parameters that you need to set to use it effectively. Except that the syntax for those parameters (it seems) varies from cmdlet to cmdlet with no discernible pattern. Unless it's a command you've been using a long time, you're going to have to look it up, and then choose the correct syntax, which can be troublesome because you must type everything letter by letter, it just begs for errors. And when you get an error, you'll scratch your head because the error message it gives you sometimes makes no sense at all. 

Who is "Kerberos?"

The POWER in "PowerShell"

The real power in PowerShell is its ability to pipeline one cmdlet into another using the "|" character (the straight line above the backslash key on your keyboard). It works like this: You type in a cmdlet and its parameters, then type the pipeline character (|), then type another cmdlet and its parameters. This allows any cmdlet to the right of the pipe to send its information into the cmdlet to the left, then wait for the error message! It's that simple! It's like having the ability to not run one cmdlet, but now you cannot run two or more at a time! That's powerful!

And you can save these cmdlets as a special text file that allows you to run large piped commands as a script! And that script can include C# elements, but the PowerShell text parser can't match the syntax, so be prepared to learn how to do THAT all over again!

Networking Blues

So, this is the conundrum: You want to use PowerShell to manage your LAN and your servers, but you need to set up and manage your LAN and your servers before you can use PowerShell. 

Oh sure, the guys in the instructional videos have no problem doing it right the first time every time, but they never show you the other computer or how to set it up. They're sending commands into the ether, and getting back data that really isn't all that helpful.

But me? I can't even connect to my Dad's PC. Ideally, I'd like to be able to monitor his processes and issue updates to his computer to keep it running when I'm not at home, but even with his computer on the same network I can't seem to connect to the damn thing, and no PowerShell tutorial I've found has been able to explain why that is. It's extremely frustrating. But that's okay -- even if I knew HOW to connect to his computer I wouldn't have the first clue as to how to do any of that management remotely, and the videos aren't really being that helpful.

"For Beginners."

I am more than halfway through the first video course on the MVA, and I am hopelessly lost. Ever since they began networking to other machines in the videos I haven't been able to keep up (because I can't follow along, because networking doesn't seem to work), and re-watching the videos has not helped. It's like they're only giving you half the information. At this point, I am so disillusioned and bitter about the whole thing that I'm not sure I want to keep going. There's a whole second part to the course that I haven't even started, because nothing they are saying at this point makes even a little bit of sense.

Let's face it, if you're a beginner you're probably going to want to steer clear of PowerShell. If you're someone who's elbows-deep in server maintenance eight hours a day, you're probably going to want to learn it at some point, and to you I say, "good luck," because you'll need it.

No comments:

Post a Comment