Bruce G. Payette9781932394900, 1932394-90-7
Table of contents :
Windows PowerShell in Action……Page 1
contents……Page 10
foreword……Page 16
freface……Page 18
Part 1 Learning PowerShell……Page 26
Welcome to PowerShell……Page 28
1.1.1 Shells, command-lines, and scripting languages……Page 30
1.1.3 The last mile problem……Page 32
1.2.1 Learning from history……Page 33
1.2.2 Leveraging .NET……Page 34
1.3 Brushing up on objects……Page 35
1.3.1 Reviewing object-oriented programming……Page 36
1.3.2 Objects in PowerShell……Page 37
1.4.1 Installing and starting PowerShell……Page 38
1.4.2 Command editing……Page 40
1.4.3 Command completion……Page 41
1.4.4 Evaluating basic expressions……Page 42
1.4.5 Processing data……Page 43
1.5 Summary……Page 48
The basics……Page 50
2.1.1 Commands and cmdlets……Page 52
2.1.2 Command categories……Page 55
2.1.3 Aliases and elastic syntax……Page 59
2.2.1 How PowerShell parses……Page 62
2.2.2 Quoting……Page 63
2.2.3 Expression mode and command mode parsing……Page 66
2.2.4 Statement termination……Page 68
2.3 Pipelines and commands……Page 70
2.3.1 Pipelines and streaming behavior……Page 71
2.3.2 Parameters and parameter binding……Page 72
2.4 Formatting and output……Page 73
2.4.1 The formatting cmdlets……Page 74
2.4.2 The outputter cmdlets……Page 76
2.5 Summary……Page 79
3.1 Type management in the wild, wild west……Page 80
3.1.1 PowerShell: a type-promiscuous language……Page 81
3.1.2 The type system and type adaptation……Page 83
3.2.1 Strings……Page 85
3.2.2 Numbers and numeric literals……Page 89
3.2.3 Collections: dictionaries and hashtables……Page 91
3.2.4 Collections: arrays and sequences……Page 96
3.2.5 Type literals……Page 100
3.3.1 How type conversion works……Page 104
3.3.2 PowerShell’s type-conversion algorithm……Page 107
3.3.3 Special type conversions in parameter binding……Page 110
3.4 Summary……Page 111
Operators and expressions……Page 112
4.1.1 The addition operator……Page 114
4.1.2 The multiplication operator……Page 117
4.1.3 Subtraction, division, and the modulus operator……Page 119
4.2 The assignment operators……Page 121
4.2.1 Multiple assignments……Page 122
4.2.2 Multiple assignments with type qualifiers……Page 123
4.2.3 Assignment operations as value expressions……Page 125
4.3 Comparison operators……Page 126
4.3.1 Scalar comparisons……Page 127
4.3.2 Using comparison operators with collections……Page 130
4.4.1 Wildcard patterns……Page 132
4.4.2 Regular expressions……Page 133
4.6 Summary……Page 138
5.1 Operators for working with types……Page 140
5.2 The unary operators……Page 142
5.3 Grouping, subexpressions, and array subexpressions……Page 144
5.4.1 The comma operator “,”……Page 148
5.4.2 The range operator……Page 151
5.4.3 Array indexing……Page 152
5.5 Property and method operators……Page 157
5.5.1 The “.” operator……Page 158
5.5.2 Static methods and the “::” operator……Page 161
5.6 The PowerShell format operator -F……Page 162
5.7 Redirection and the redirection operators……Page 163
5.8 Variables……Page 166
5.9 Summary……Page 170
Flow control in scripts……Page 172
6.1 Using the if/elseif/else statement……Page 173
6.2 The while loop……Page 176
6.3 The do/while loop……Page 177
6.4 The for loop……Page 178
6.5 The foreach loop……Page 180
6.6 Labels, break, and continue……Page 184
6.7.1 Basic use of the PowerShell switch statement……Page 186
6.7.2 Using wildcard patterns with the switch statement……Page 188
6.7.3 Using regular expressions with the switch statement……Page 189
6.7.4 Processing files with the switch statement……Page 192
6.7.5 Using the $switch loop enumerator in the switch statement……Page 193
6.8 Flow control using cmdlets……Page 194
6.8.1 The Foreach-Object cmdlet……Page 195
6.8.2 The Where-Object cmdlet……Page 198
6.9 The value of statements……Page 200
6.10 Summary……Page 201
Functions and scripts……Page 202
7.1 Function basics……Page 203
7.2 Formal parameters and the param statement……Page 206
7.2.1 Specifying parameter types……Page 208
7.2.2 Handling variable numbers of arguments……Page 210
7.2.3 Initializing function parameters……Page 211
7.2.4 Using switch parameters to define flags……Page 213
7.2.5 Variables and scoping rules……Page 215
7.3 Returning values from functions……Page 218
7.3.1 Debugging function output……Page 221
7.3.2 The return statement……Page 223
7.4 Using functions in a pipeline……Page 224
7.4.1 Filters and functions……Page 226
7.4.2 Functions as cmdlets……Page 227
7.5 Managing functions……Page 229
7.6 Scripts at long last……Page 230
7.6.1 Passing arguments to scripts……Page 232
7.6.3 Scopes and scripts……Page 233
7.6.4 Exiting scripts and the exit statement……Page 234
7.6.5 Dotting scripts and functions……Page 235
7.7 Summary……Page 237
Scriptblocks and objects……Page 239
8.1 Scriptblock basics……Page 240
8.1.1 Invoking commands……Page 241
8.1.2 Getting CommandInfo objects……Page 242
8.1.3 The ScriptBlock literal……Page 244
8.1.4 Defining functions at runtime……Page 245
8.2.1 Looking at members……Page 247
8.2.2 Synthetic members……Page 248
8.2.3 Using Add-Member to extend objects……Page 249
8.2.4 Using the select-object cmdlet……Page 255
8.3 A closer look at the type-system plumbing……Page 258
8.3.1 Adding a property……Page 260
8.3.2 Shadowing an existing property……Page 261
8.4.1 Little languages……Page 262
8.4.2 Adding a CustomClass keyword to PowerShell……Page 263
8.5 Type extension……Page 268
8.6.1 The Invoke-Expression cmdlet……Page 270
8.6.2 The ExecutionContext variable……Page 271
8.6.3 Creating functions using the function: drive……Page 273
8.7 Summary……Page 274
Errors, exceptions, and script debugging……Page 276
9.1 Error handling……Page 277
9.1.1 ErrorRecords and the error stream……Page 278
9.1.2 The $error variable and -ErrorVariable parameter……Page 281
9.1.3 The $? and $LASTEXITCODE variables……Page 284
9.1.4 $ErrorActionPreference and the -ErrorAction parameter……Page 286
9.2.1 The trap statement……Page 290
9.2.2 The throw statement……Page 293
9.3.1 Debugging with the host APIs……Page 295
9.3.3 Tracing statement execution……Page 296
9.3.4 Stepping through statement execution……Page 300
9.3.5 Catching undefined variables with strict mode……Page 301
9.4.1 Suspending a script while in step-mode……Page 302
9.4.2 Creating a breakpoint command……Page 304
9.4.3 The script call stack, or “How did I get here?”……Page 306
9.5.1 The Trace-Command cmdlet……Page 308
9.5.2 Tracing type conversions……Page 310
9.5.3 Tracing parameter binding……Page 312
9.6.1 Examining the event log……Page 316
9.7 Summary……Page 318
Part 2 Using PowerShell……Page 320
Processing text, files, and XML……Page 322
10.1.1 Using System.String to work with text……Page 323
10.1.2 Using regular expressions to manipulate text……Page 329
10.2 File processing……Page 330
10.2.1 Working with PSDrives……Page 332
10.2.2 Working with paths that contain wildcards……Page 334
10.2.3 Reading and writing files……Page 338
10.2.4 Searching files with the Select-String cmdlet……Page 344
10.3.1 Using XML as objects……Page 347
10.3.2 Loading and saving XML files…….Page 351
10.3.3 Processing XML documents in a pipeline……Page 358
10.3.4 Using XPath……Page 359
10.3.5 The Import-Clixml and Export-Clixml cmdlets……Page 364
10.4 Summary……Page 367
Getting fancy- .NET and WinForms……Page 369
11.1.1 .NET basics……Page 370
11.1.2 Working with assemblies……Page 371
11.1.3 Finding types……Page 373
11.1.4 Creating instances of types……Page 375
11.1.5 PowerShell is not C#-A cautionary tale……Page 378
11.1.6 Working with generic types……Page 383
11.2.1 Example: Retrieving a web page……Page 386
11.2.2 Example: Processing an RSS feed……Page 387
11.2.3 Example: Writing a web server in PowerShell……Page 389
11.3.1 WinForms basics……Page 396
11.3.2 Example: “My first form”……Page 397
11.3.3 Example: Simple dialog……Page 399
11.3.4 Example: A WinForms library……Page 401
11.3.5 Example: A simple calculator……Page 404
11.3.6 Example: Displaying data……Page 410
11.3.7 Example: Using the GDI+ to do graphics……Page 412
11.4 Summary……Page 416
Windows objects: COM and WMI……Page 417
12.1 Working with COM in PowerShell……Page 418
12.1.1 Automating Windows with COM……Page 421
12.1.2 Networking, applications, and toys……Page 430
12.1.3 Using the ScriptControl object……Page 440
12.1.4 Issues with COM……Page 442
12.2.1 Exploring WMI-what is it, and why do you care?……Page 446
12.2.2 The Get-WmiObject cmdlet……Page 447
12.2.3 The WMI object adapter……Page 448
12.2.4 WMI shootout-VBScript versus PowerShell……Page 450
12.2.5 The WMI type shortcuts……Page 454
12.2.6 Working with WMI methods……Page 457
12.2.7 Working with WMI events……Page 458
12.2.8 Putting modified WMI objects back……Page 459
12.4 Summary……Page 462
Security, security, security……Page 465
13.1.2 What security is not……Page 466
13.1.3 Perception and security……Page 467
13.2 Security modeling……Page 468
13.2.2 Classifying threats using the STRIDE model……Page 469
13.2.3 Security basics: Threats, assets, and mitigations……Page 470
13.3.1 Secure by default……Page 474
13.3.2 Managing the command path……Page 475
13.3.3 Choosing a script execution policy……Page 476
13.4.1 How public key encryption and one-way hashing work……Page 478
13.4.2 Signing authorities and certificates……Page 479
13.4.3 Creating a self-signed certificate……Page 480
13.4.4 Using a certificate to sign a script……Page 483
13.4.5 Enabling strong private key protection for your certificate……Page 487
13.5.1 Using the SecureString class……Page 490
13.5.2 Working with credentials……Page 493
13.5.3 Avoiding Invoke-Expression……Page 496
13.6 Summary……Page 499
A.1 PowerShell and cmd.exe……Page 501
A.1.1 Basic navigation and file operations……Page 502
A.1.2 Variables and substitution……Page 503
A.1.4 Differences in syntax……Page 505
A.1.6 For loop equivalents……Page 507
A.1.7 Batch files and subroutines……Page 508
A.1.8 Setting the prompt……Page 509
A.1.9 Using doskey in PowerShell……Page 510
A.1.10 Using cmd.exe from PowerShell…….Page 512
A.2.1 Example: Stopping all processes……Page 513
A.2.2 Example: Stopping a filtered list of processes……Page 514
A.2.4 Example: Working with dynamic values……Page 515
A.2.6 Example: Checking for prerelease binaries……Page 516
A.2.8 Example: Inserting text into a string……Page 517
A.3 PowerShell and Perl……Page 518
A.4.1 Calling functions and commands……Page 519
A.4.4 Variables and scoping……Page 520
A.5 PowerShell and VBScript……Page 521
B.1 Getting active directory domain information……Page 524
B.2 Listing installed software features……Page 525
B.3 Retrieving terminal server properties……Page 526
B.4 List hot fixes installed on a machine……Page 527
B.5 Finding machines missing a hot fix……Page 528
B.6 Working with the event log……Page 530
B.6.1 Getting a specific EventLog object……Page 531
B.6.2 The event log as a live object……Page 532
B.6.3 Getting remote event logs……Page 533
B.6.4 Saving event logs……Page 534
B.7 Working with existing utility commands……Page 535
B.8 Working with Active Directory and ADSI……Page 537
B.8.2 Adding a user……Page 538
B.8.3 Adding a group of users……Page 539
B.8.4 Updating user properties……Page 541
B.8.5 Removing users……Page 542
B.9 Joining two sets of data……Page 543
C.1 Statement list……Page 545
C.2.1 Pipeline……Page 546
C.2.3 The switch statement……Page 547
C.2.5 The for and while statements……Page 548
C.2.8 The finally statement……Page 549
C.2.10 Function declarations……Page 550
C.3 Expression……Page 551
C.4 Value……Page 552
C.5 Tokenizer rules……Page 553
index……Page 556
Reviews
There are no reviews yet.