By best advice when troubleshooting VBScript is to go back to basics. Build your script in sections. Get each scriplet working, then bolt all the parts together and so
re-create your script. If you embrace this strategy, then search for a similar script, on this site, copy and paste the script, fine tune the commands to your circumstances and get that section working.
Repeat for the next section of your script.
What I like to do when troubleshooting is keep halving the search area until the
problem emerges. The way
that I narrow the search area is to
ask a series of questions, for example, is the error down to syntax or logic. A logical error would be trying to connect to a server or share that does not exist, whereas a syntax error
would be a missing bracket or ampersand.
Here are pairs of questions each of which narrow the search area. The problem is 'Why doesn't my VBScript work?'
Is the problem Logical or Syntax
Should we look at the VBscript or to Active Directory
Server or Client (especially Win 9x)
Is the error consistent or intermittent
Always remember that scripts mimic real life. Therefore, walk through the actions manually and record all the steps. For example, open Active Directory Users and Computer and manually
create the user or amend the property sheet. Now go back to the script and see if you can find the missing item.
Can you run the script successfully on the very Windows 2003 server? Simply double click
the VBScript in isolation, away from a Group Policy. This test will determine if you're facing a pure VBScript problem, or if the error is assigning the script via Active Directory Users and Computers.
If absolutely nothing happens, check the file extension. You need to save as
with a .VBS extension. Is security so tight that VBScript files are forbidden from executing?
In terms of strategy, break the script down into sections. Get each section working
in isolation, then paste all the sections together and so build the final script.
After you get the script working on the server, the next step it to run the script on the
client. Does it work on an XP Client? Is the
fault only with Windows 9x machines?
Do you get an error message in a Windows Script Host box?
When the VBScript fails, research each of the clues supplied in the message box. Read the Error: Xyz message. Check the Line number
in the message against the line number in your script. Count all blank lines and comments.
The Engineer's Toolset v10 provides a
comprehensive console of utilities for troubleshooting computer problems. Guy says
it helps me monitor what's occurring on the network, and the tools
teaches me more about how the system literally operates.
There are so many good gadgets, it's like having free rein of a
sweetshop. Thankfully the utilities are displayed logically: monitoring, discovery, diagnostic, and Cisco tools.
Download your copy of the Engineer's Toolset v 10
For a quick fix, try adding the command 'On Error Resume Next'.
This tells the script to ignore the error and continue. In my opinion this is seldom a permanent solution, however it will allow the script to get past the fault and possibly execute useful
commands. One possible use of this strategy is when you are mapping multiple network drives. On Error Resume Next would skip the fault and at least VBScript will map the other drives.
Option Explicit
This
command forces you declare all variables. Where Option Explicit helps your troubleshooting is where you misspell a variable later in the script. For example, you start off calling it strUser
but
then call it strUserS.
Err.Number
Err.number is the first stage in introducing proper error-correcting code. Combined with If ..then... End If, Err.number offers
professional
solutions to your problem. The only trouble is that you need experience of both the If ..then structures and the possible logical outcomes. Perhaps my ideas for err.number are best explained
by an example:
' Sub Routine Sub GuyCase()
' Select Case (Not Case Select!) errLogonScript = err.number Select Case errLogonScript Case vbEmpty strError = "No Problem " Case -2147024811 strError = "Drive already in use " Case -2147023665
strError = "Check server name " Case -2147023693 strError = "Check share name " Case -2147024829 strError = "Another share name problem " ' Finish with Case Else in order to catch exceptions Case
Else strError = "Research this number: " End Select WScript.Echo strError & err.number ' Wscript.Echo "Errors = " '& err.count err.clear err.number = vbEmpty End Sub
When you
try to connect to a specific folder in Active Directory, you get a
specific message:
Error: There is no such object on the server Code: 80072030 Source: (null)
I am going to take a wild guess here, there is something wrong with the line in the script that references
the OU, if it's one of my scripts, the line referencing: strContainer = "OU=Droitwich,".
Your problem could be as simple as a missing comma, or it could be that you don't have an
OU called Droitwich.
The reason for clarifying the difference between OU
and CN (Container) is when you start building Active Directory scripts. It is easy to make a mistake and try to script CN=Accounts, or OU=Users, when it should be OU=Accounts and
CN=Users.
A reminder that the variable strContainer is part of a longer string, for example OU=Droitwich,DC=CP,DC=com.
If you are scripting a child OU, then the correct syntax would be "OU=Child,OU=Droitwich," The way I remember the sequence is to imagine the user's full DN (distinguished name), the syntax would be:
If you need a temporary work-around to the child / parent problem, create a test OU, with a test user off the root of your domain. My idea is to build on success, get this simpler example working
then revisit the child / parent OU relationship. OU=test,DC=CP,DC=com. I mention as this because so many people create ridiculously long
paths that say to me: you are bound to make a mistake somewhere; this is by no means the longest example that I have seen: "OU=Maybe a space,OU=sub-hyphen,OU=Child,OU=Droitwich,DC=CP,DC=com".
Be, methodical, be disciplined and try only one remedy at a time. Above all start simply, get the basic VBScript working and only then add complexity to get to the final production script.
Their topics and material are ideal for getting you started with VBScript. The
videos are easy to follow and you can control the pace. Try their free demo material and then see if you want to buy the full package.
See more about VB Script Training CD.
The extra features you get in your eBook
include, more pages full of detailed examples. Also, ten 'how to...'
sections, with screen shots showing which menus to use. Go for Guy's
eBook - and get a printable version with copy enabled and no expiry date.