Managing Windows Networks Using Scripts – Part 5: Getting Over the Hump

If you would like to read the other parts in this article series please go to:

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.


Pre-order your copy of the Microsoft Windows Vista Resource Kit today!

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 customized our original script to make it do something different. Specifically, we took a script that changed the IP address of a network adapter and customized 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.

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 and you answering them by saying “Here are some addresses of different cooking schools, titles of cookbooks, websites etc.—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?

Well I tried to become a gourmet cook once, and here’s how I went about it:

  1. I bought a bunch of old issues of Gourmet Magazine from a local second-hand bookstore and started reading them.
  2. I started buying all sorts of exotic ingredients like herbs and spices, different oils, and so on.
  3. 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).
  4. 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.)
  5. The day of the dinner date came, and I began cooking this famous soup—for the first time i.e. 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. Plus 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:

  1. I started out at way too high a level, trying to prepare something that required a lot of basic skills that I hadn’t yet acquired.
  2. I failed to test my creation properly before rolling it out “in production”.
  3. I couldn’t understand the difference between learning a concept and learning a skill.
  4. 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?

  1. Take a basic course in French cooking offered evenings by a local community club.
  2. Learn how to make a simple white sauce before trying anything tougher.
  3. Learn new cooking terms gradually instead of trying to read a highbrow magazine like Gourmet.
  4. Practice, practice, practice before I started to experiment and be original.
  5. Find other ways to attract dates i.e. by learning to groom myself.

What does this have to do with learning to script? Well first of all, a little humor like this puts you in the mood to be receptive 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 porkchop. I know I would get bored silly after only a few weeks and would 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:

  1. 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 customize 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.
  2. 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.
  3. 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.
  4. 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 customize it a bit. But MSDN was like Greek to me (no offense 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.
  5. 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’s these articles, too!
  6. 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 doesn’t have lumps in it! The same with learning to script: repetition makes perfect. There will be humps along the way of various sizes, and it will take determination and persistence to get over them. And generally speaking, you will learn more from writing several hundred short scripts than trying to write a few long and complex ones. So setting yourself a series of short exercises as goals and doing them is an excellent way to learn.
  7. It’s gotta be fun. Finally, I don’t know about you but I learn best when it’s fun. If you have some administration tasks on your network that you think scripting might make easier, then that’s one possible motivation to learn to script. On the other hand, if you’re really busy (and what network administrator isn’t) then it might be easiest if you get someone else to write the scripts for you. But if you approach scripting as a new hobby to enjoy, similar to golf, then you’ll probably learn faster and be able to do more with what you learned than if you approach it as another chore on your overloaded To Do list. And just as golf is most enjoyable when played with others, see if some of your IT pro friends or colleagues might also be interested in playing the scripting game. Sharing what you’re learning with others makes it even more fun.

Conclusion

I wrote this article because I sensed from some readers that they were already approaching The Hump after only four articles. Hopefully what I’ve said here will help you overcome whatever is holding you back from really learning this stuff. In my next article we’ll return to exploring the Win32_NetworkAdapter Configuration class and see what we can do with it, and along the way we’ll learn new concepts and reinforce ones previously introduced. We’ll also learn additional bits and pieces of the VBScript syntax and see how we can make our scripts more elegant and useful. And then we’ll explore some other WMI classes and eventually some advanced scripting topics like alternate credentials, remote scripting, COM objects, WSF scripts, and so on. We’ll eventually tap into a few tools useful for writing scripts, but it’s important to learn the basics first before you learn the shortcuts as it gives you a much deeper understanding of the subject and therefore more confidence in your skills. I’ll also try to give you some exercises to complete on your own, and if you really want to learn to script you need to do them and not just look at them and say “I can do that.” After all, practice does make perfect. And finally, feel free as always to email me if you have any questions or suggestions concerning this series of articles. Good luck!

If you would like to read the other parts in this article series please go to:

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top