PREVIOUSLY: Using Win32_NetworkAdapterConfiguration
When learning to script for managing Windows networks, you need to be aware of a bump in the road Mitch Tulloch calls "the hump." Learn how to get over the hump in this tip.
In the previous article in this series we started exploring what we could do with the Win32_NetworkAdapterConfiguration class. This powerful WMI class has 61 properties and 41 methods that can be used for retrieving and changing TCP/IP networking settings on Windows computers.
To illustrate the power of this class, we took the sample script we developed in the first and second articles, and using information about this class on MSDN, we customised our original script to make it do something different. Specifically, we took a script that changed the IP address of a network adapter and customised it to come up with a new script that disables NetBIOS over TCP/IP (NetBT) on all network adapters that have TCP/IP bound and enabled on them.
We need to explore this powerful WMI class further, and we're going to do so in several future articles. But before we do this, let's talk about "the hump."
After I began this series of articles on how to manage Windows networks using scripts, I started to get emails from readers. Most of these emails involved readers asking a simple question: "How can I learn to script?" My initial reaction is usually to point the questioner to a variety of resources including articles on TechNet, different books, scripting newsgroups, and so on. Of course, when I think about it, that's like saying to someone who asks you how to become an expert in French cooking, "Here are some addresses of different cooking schools, titles of cookbooks, and websites. Go, start learning." That kind of answer may be helpful to those who have the initiative and self-discipline to learn a skill themselves, but it poses another question that's more interesting: Why do some of us have difficulty learning a skill in the first place?
I tried to become a gourmet cook once, and here's how I went about it:
- I bought a bunch of old issues of Gourmet Magazine from a local second-hand bookstore and started reading them.
- I started buying all sorts of exotic ingredients like herbs and spices, different oils, and so on.
- I picked what sounded like a really tasty recipe called "Carrot Ginger Soup Frog" and bought all the ingredients for it. (Frog is the name of the restaurant where the chef worked who created this soup; i.e. there are no frogs in the soup).
- I invited several friends of the female persuasion to a dinner where I planned to present this culinary wonder for their gastronomic amazement. (Note that I said several friends, not one. If you're going to get lucky you sometimes need to use a net instead of a hook.)
- The day of the dinner date came, and I began cooking this famous soup for the first time. I didn't practice beforehand.
What was the result of all this? Soup all over the place, on the stovetop, on the walls, on the ceiling. And dirty pots and pans piled sky high. I didn't get lucky either -- it didn't taste all that great, either to my friends or to me. What went wrong? A lot of things. Specifically:
- I started out at way too high a level, trying to prepare something that required a lot of basic skills I hadn't yet acquired.
- I failed to test my creation properly before rolling it out "in production."
- I couldn't understand the difference between learning a concept and learning a skill.
- I hadn't even applied myself to learning concepts diligently, let alone skills.
What kind of approach should I have followed instead of the one I used?
- Take a basic course in French cooking offered evenings by a local community club.
- Learn how to make a simple white sauce before trying anything tougher.
- Learn new cooking terms gradually instead of trying to read a highbrow magazine like Gourmet.
- Practice, practice, practice before I started to experiment and be original.
- Find other ways to attract dates, such as learning to groom myself.
What does this have to do with learning to script? Well first of all, a little humour like this puts you in the mood to to listen, and now that I have your ear maybe you'll hear what I have to say. Almost every Windows administrator who wants to learn how to script usually hits a big bump in the road along the way, which I'll call "the hump." This hump appears when the brain starts to shut down because there are just too many concepts to absorb easily. This is because concepts don't exist in a vacuum, they are interrelated. For example, you can't really understand what a Property is unless you also grasp what a Method is. And both Properties and Methods are only understood in the context of Classes. And Classes must be Instantiated into Objects before they can have Properties and Methods, or more properly, Object References to the Instance of a Class have Properties and Methods you can read and manipulate. Sounds like gobbledygook, doesn't it? Well, that's because it is gobbledybook!
"Why can't I just learn to script? Why do I have to learn all these concepts and terminology?" Well, why do you have to learn the difference between a white sauce and brown sauce? Or know that sauces come in four basic types: purees, reductions, starch-bound and emulsions? Or that roux forms the basis for bechamel, veloute, etouffe and both white and brown sauce? And why do I need to understand the history of bechamel? Because in the long run you won't get anywhere unless you learn these basic concepts, as they (and many others) form the basis of most French cooking.
On the other hand, most of us in the real world (i.e. those of us who don't want to become professional chefs) don't have the time, money or patience to attend a French cooking school full time and spend the first six months making basic sauces again and again before we are taught how to fry a pork chop. I know I would get bored silly after only a few weeks and decide I better find a different career. It's the same with learning to script: As a busy network admin, I just can't spend three years learning every Property and Method associated with every WMI class that has anything to do with Windows networking. Or learn every aspect of the syntax of the VBScript language to become totally proficient in it. I had enough of that learning Fortran back in my freshman university days, writing program after program to print out the first ten squares, the first 100 primes, the first thousand Fibonacci numbers, and so on and so on. So given our limited time, money and patience, coupled with the intrinsic difficulty of learning the vast number of interrelated concepts involved in Windows scripting, how can ordinary administrators like us get over the hump and learn to script -- and do it usefully?
Getting over the hump
Clearly there's no magic answer to this question, but there are some things I've found helpful. Here's what's helped me:
- Start small. Shooting for the sky is not a good place to begin, either for learning French cooking or how to script. So if you have set your goal to learning how to write a script to query Active Directory for the OU structure in a domain and display this structure in an HTML page, and to learn enough to write this script in a week, then you're probably shooting too high, or at least you're a lot smarter than me. What you'll likely do is Google for scripts that do something similar to this and try and customise these scripts to make them fit your needs (and that's all right), but it's only one aspect of learning. Plus you may end up with a complex script that you don't completely understand.
- Focus on a specific area of scripting. One of my own biggest weaknesses is that I want to learn everything about everything, and learn it now. So when I first wanted to learn how to script, I started by trying to read through the entire VBScript Language Reference from beginning to end. Needless to say, it was dry reading and I gave up about a quarter of the way through. It's much better to focus on one specific area of scripting, such as scripting TCP/IP networking tasks, which is the focus of this series of articles. Once you've mastered this (not so small) area of scripting, you can then move on to another focused area and try to master it, and so on.
- Take some time to learn the basics. While focusing in on one topic area is a good idea, it's also important just to learn the basics. Learn how to input information into a script using runtime parameters. Learn how to handle simple errors. Learn how to display results in a readable way. Learn some simple SELECT statement syntax. Learn the different variable types. Learn some of the key WMI classes, and learn a couple of useful Properties and Methods for each class. And so on. You don't have to become an expert in all of these areas, but you need to know enough about each of them in order to write a decent script as opposed to a mere script fragment.
- Keep notes on what you've learned. For a long time (embarrassingly long) I was frustrated in my attempts at learning to script because of some of the concepts involved. As you may have guessed from my earlier comment about learning Fortran in university, I learned computer programming in the days of procedural programming. This resulted in ingrained thinking that made it difficult for me to switch to object-oriented programming when this started to become popular (for Windows admins) when VBScript was spun off from Visual Basic. So for a long time, I was stymied by the terminology Object, Property, Method, Class and so on, and it created a big obstacle (the hump) for me to learn to script. Sure, I could take a script someone else had written and (if it was simple enough) I could more or less figure out how it worked and be able to customise it a bit. But MSDN was like Greek to me (no offence intended to Hellenes) and WMI was a total mystery. Until I started taking notes. One day I wrote down a simple statement that "Properties are things you can read while methods are things you can do" and suddenly the hump became a molehill, and I was over it. Other concepts quickly started falling into place because they're so connected; once you have a few of then pinned down, the rest start quickly falling into place.
- Collect useful learning resources and use them. If you find a good book on scripting, buy it and read it through from cover to cover, doing the exercises. There are also great resources on the TechNet Script Center and I'll be highlighting some of these in future articles in this series. Other resources include courses (both instructor led and self-paced), discussion groups, and so on. There's no shortage of good resources out there on learning to script; the key is to make good use of several of them so you get somewhere. There are these articles, too!
- Practice, practice, practice. Learning any skill well takes a great deal of patience. In fact, I still can't make a decent white sauce that