xiv
Contents
Control Loops .....................................................................................................................30
For Next looping .......................................................................................................30
For Each looping ....................................................................................................... 31
Using Exit For ..........................................................................................................32
Using Do While loops ...............................................................................................32
Using Do Until loops ................................................................................................33
Using Exit Do ...........................................................................................................34
While…WEnd loops .................................................................................................34
Using Procedures ................................................................................................................34
Working with functions ............................................................................................ 35
Working with subroutines ........................................................................................37
Summary ............................................................................................................................38
JScript Essentials
Chapter 3:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Variables and Data Types ....................................................................................................39
Variables and naming conventions ...........................................................................39
Working with data types ..........................................................................................40
Using Strings ...................................................................................................................... 41
Concatenating strings ............................................................................................... 41
Converting to and from strings ................................................................................. 42
Using Comments ................................................................................................................ 42
Using Arrays ....................................................................................................................... 42
JScript Operators ................................................................................................................44
Arithmetic operators .................................................................................................44
Comparison operators ..............................................................................................45
Assignment operators ............................................................................................... 47
Logical operators ...................................................................................................... 47
Bitwise operators ......................................................................................................49
Conditional Statements ......................................................................................................49
Using if .....................................................................................................................49
Using if…else ............................................................................................................50
Control Flow with Looping ................................................................................................50
Using for loops ..........................................................................................................50
Using for in loops......................................................................................................50
Using while and do while loops ................................................................................ 51
Using continue and break statements .......................................................................52
Using switch case .....................................................................................................52
Using Functions .................................................................................................................53
Function structure ....................................................................................................54
Calling functions ......................................................................................................54
Summary ............................................................................................................................ 55
PowerShell Fundamentals
Chapter 4:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Shell Fundamentals ............................................................................................................57
PowerShell Aliases ..............................................................................................................58
86804ftoc.indd xiv
86804ftoc.indd xiv
1/22/09 11:53:41 AM
1/22/09 11:53:41 AM
xv
Contents
Cmdlets,
Snap-ins, and Providers .....................................................................................60
Functions and Filters ..........................................................................................................62
Objects and Types and the PowerShell Pipe .......................................................................63
Exploring PowerShell Variables ..........................................................................................65
Richer Types and .NET Objects ..........................................................................................69
Arrays .................................................................................................................................73
The PowerShell Pipe ........................................................................................................... 74
Looping in PowerShell ........................................................................................................77
Conditions ..........................................................................................................................80
Scripts,
Script Blocks, and Functions .................................................................................83
Scripts and Security ..........................................................................................................85
Summary ............................................................................................................................88
Part II: Windows VBScript and JScript
Creating Scripts and Scripting Files
Chapter 5:
. . . . . . . . . . . . . . . . . . . . . . . . 91
Running Scripts .................................................................................................................. 91
Starting a Script ........................................................................................................92
Setting script properties ............................................................................................92
Command-line options for scripts ............................................................................93
Using drag and drop with scripts .............................................................................95
Creating Batch Scripts ........................................................................................................96
Identifying the job name ..........................................................................................97
Adding scripts and setting the scripting language ....................................................98
Setting the script source ...........................................................................................98
Referencing external objects and type libraries ......................................................100
Setting job properties .............................................................................................. 102
Setting parsing instructions .................................................................................... 103
Documentation and Usage ......................................................................................104
Summary ..........................................................................................................................106
VBScript and JScript Scripting Basics
Chapter 6:
. . . . . . . . . . . . . . . . . . . . . 107
Key WSH Objects ............................................................................................................. 107
Displaying Text Strings ....................................................................................................109
Using Echo .............................................................................................................109
Running the Echo script ......................................................................................... 110
Examining Script Information .......................................................................................... 110
Getting script host information .............................................................................. 110
Getting scripting information ................................................................................. 113
Getting script arguments ........................................................................................ 115
Working with Environment Variables .............................................................................. 117
Understanding environment variables .................................................................... 117
Accessing environment variables ............................................................................ 118
Working with environment variables: An alternative ............................................. 119
86804ftoc.indd xv
86804ftoc.indd xv
1/22/09 11:53:41 AM
1/22/09 11:53:41 AM