Script Tips

Manual Labor

Break down your scripts into segments to debug them. Simple, but not many go through the process.

This week is the third — and last — in a series of tips on VBScript debugging.

This’ll seem like an obvious thing, but in the heat of trying to get a complex script to work, it can often go overlooked: Debug manually.

What’s that mean? First, break your script down into segments, with each segment performing some specific task. Then, try to perform those tasks manually, without a script. You’ll often be able to spot the problem right away, since the Windows UI will describe problems in more detail than script errors.

What many folks often overlook with this method is the need to compare “apples to apples.” In other words, you should be manually doing exactly what your script is doing. If your script is trying to create a new folder on \\Server2\Share1, manually try and do the same thing. If your script is running under alternate credentials (using RunAs, perhaps), you should manually attempt the task using those same credentials (you can see how doing otherwise might provide different results).

Also, spend a moment thinking about what your script is doing and how Windows operates. Here’s an example: Suppose you write a script that modifies several shortcuts located in a user’s profile. You assign the script as a startup script in Active Directory, but no shortcuts are modified.

Why? Think about it: Startup scripts run when the computer logs on to the domain. At that point, there’s no user logged on, so there’s no user profile to work with. So your script is trying to work with something — a user profile — that doesn’t exist right then. The script would be better deployed as a logon script, so it’d have a user profile to mess with. This is a good example of a script that should work fine, but doesn’t simply because of the way in which it’s being utilized.

Taking a quick breather and walking through your script’s actions, and thinking about the context in which they’ll be running, can save a lot of time and make your debugging much more effective.

About the Author

Don Jones is a multiple-year recipient of Microsoft’s MVP Award, and is Curriculum Director for IT Pro Content for video training company Pluralsight. Don is also a co-founder and President of PowerShell.org, a community dedicated to Microsoft’s Windows PowerShell technology. Don has more than two decades of experience in the IT industry, and specializes in the Microsoft business technology platform. He’s the author of more than 50 technology books, an accomplished IT journalist, and a sought-after speaker and instructor at conferences worldwide. Reach Don on Twitter at @concentratedDon, or on Facebook at Facebook.com/ConcentratedDon.

comments powered by Disqus
Most   Popular