Guy's Scripting Ezine 41 - Case Select
Contents for Guy's Scripting Ezine 41 - Case Select
20 years ago I gave up playing 'Shoot em up' games. These days I get the same kick from 'playing' with VBScript. This week's indulgence is Case Select statements.
Guy Recommends: The Free IP Address Tracker (IPAT)
Calculating IP Address ranges is a black art, which many network managers solve by creating custom Excel spreadsheets. IPAT cracks this problem of allocating IP addresses in networks in two ways:
For Mr Organized there is a nifty subnet calculator, you enter the network address and the subnet mask, then IPAT works out the usable addresses and their ranges.
For Mr Lazy IPAT discovers and then displays the IP addresses of existing computers. Download the Free IP Address Tracker
Scenario: Which drives are in use? What sort of disk corresponds to each drive letter? Is it a hard disk, network drive or floppy drive?
Note 1: The script relies on a For Each..... Next loop.
Note 2: The featured command is: Select Case.... End Select. Inside the statement are your series of values, Case 1 =, Case 2= etc.
SolarWinds' Orion performance monitor will help you discover what's happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
Scenario: You wish to check the name and the 'Status' of your printers.
'Case Select' is a useful technique where you have a list of possible outcomes. Admittedly, you could use multiple 'Else If' statements, but Case Select is a more elegant solution.
WMI is the way of the future, never waste a chance to learn how VBScript can quiz the operating system. Variables offer great techniques for controlling scripts. For example, it is useful to control a value from a central location, usually at the start of the script.
See more about VBScript techniques