Microsoft PowerShell, VBScript and JScript Bible

Microsoft PowerShell, VBScript and JScript Bible

William R. Stanek

Language: English

Pages: 912

ISBN: 0470386800

Format: PDF / Kindle (mobi) / ePub

Packed with more than 300 sample scripts and an extensive collection of library functions, this essential scripting book is the most thorough guide to Windows scripting and PowerShell on the market. You’ll examine how Windows scripting is changing the face of system and network administration by giving everyday users, developers, and administrators the ability to automate repetitive tasks. Plus, this is the first time that VBScript, Jscript, and Powershell are all covered in a single resource.














and choice equals Y //execute these statements } else { //condition is false and choice doesn’t equal Y //execute these statements } Control Flow with Looping Sometimes you want to repeatedly execute a section of code. You can do this several ways in JScript. You can use: ■ for and for in ■ while and do while ■ switch case Using for loops Using for loops in your code is easy. The following example uses this structure to initialize an array of ten elements: for (x = 0; x < 10; x++) {

Cmdlets are usually in the form: Verb-Noun Another PowerShell command, Get-Command, takes –Verb or –noun switches, so the command: Get-Command –verb get will give a list of all the commands that start with get-. This is important because it enforces consistency. If you think about different ways in Windows that you might get information or stop something you’ll understand that there is a lot of vocabulary to memorize. Stopping a service might use the Net command with a stop parameter, stopping

and are set during user login. These user variables are valid only for the current user and are not available for other users. Table 6-4 lists the key built-in system and user variables you may want to work with in shell scripts. Additional variables can be created by users and the operating system. TABLE 6-4 Built-in System and User Variables Variable Name Description Sample Value ALLUSERS PROFILE Default profile for users F:\Documents and Settings\ All Users APPDATA Location of the

info = ScriptEngine & “ Version “ info = info & ScriptEngineMajorVersion & “.” info = info & ScriptEngineMinorVersion & “.” info = info & ScriptEngineBuildVersion GetInfoVB = info End Function continued 127

failure. Try again?”, timeOut, title, button) return answ } The return value from Popup tells you which button the user selected. Return values are the same as those listed previously in Table 7-3, but with one important addition. If the user doesn’t press a button and the timeout interval elapses, the method returns –1. 139 86804c07.indd 139 1/21/09 1:25:44 PM Part II Windows VBScript and JScript Listing 7-3 shows how you can handle user selections and errors in both VBScript and

Download sample