Pro Windows PowerShell 9781590599402, 1590599403, 9781430205463, 1430205466, 9781590599

I remember the first time I got to play with Windows PowerShell--I had some spare time on my hands, and after reading a

164 93 11MB

English Pages 493 [519] Year 2008

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Pro Windows PowerShell......Page 1
Contents at a Glance......Page 6
Contents......Page 9
About the Author......Page 19
About the Technical Reviewer......Page 21
Acknowledgments......Page 23
What’s in This Book?......Page 25
Do I Need Prior Programming Experience?......Page 26
The Extended Type System......Page 27
Using Object Methods......Page 28
ManagementObjectAdapter......Page 29
DataRowAdapter......Page 30
Type Extensions......Page 31
Strings and String Operations......Page 34
String Literals......Page 35
String Interpolation......Page 37
Productivity Boosting String Operators......Page 38
Regular Expression Matching......Page 39
System.Int32......Page 40
Hexadecimal Numbers......Page 41
Arrays and Collections......Page 42
Dictionaries and Hash Tables......Page 47
Type Literals......Page 51
Type Conversion......Page 52
Built-in Type Conversion Rules......Page 53
Accessing Static Members......Page 56
Summary......Page 57
Conditional Expressions......Page 59
Comparing Values......Page 60
Implicit Type Conversions......Page 62
-or......Page 63
-not......Page 64
Boolean Conversions......Page 67
The Power of String Conversions......Page 68
Collections and Conditional Expressions......Page 69
Simple Branching: if/else......Page 70
Multiple Branches and the switch Statement......Page 71
The Simplest Loop: while......Page 74
Executing Actions on All Objects in a Collection: The foreach Loop......Page 76
Controlling Loop Execution: break and continue Statements......Page 77
Summary......Page 80
Text-Based Pipelines......Page 81
Object-Based Pipelines......Page 82
Processing Collections Using ForEach-Object......Page 85
Adding or Deleting Properties Using Select-Object......Page 86
Sorting Collections......Page 88
Pipeline Tees......Page 89
Grouping Objects......Page 90
Detecting Changes and Differences Among Objects......Page 91
The Object Pipeline and Functional Programming......Page 92
Summary......Page 93
Defining Script Blocks......Page 95
Passing Parameters and Returning Values......Page 97
Processing Pipeline Input......Page 101
Variable Scope......Page 103
Invoking Strings as Expressions......Page 109
Script Blocks as Delegates......Page 111
Summary......Page 112
Defining Functions......Page 113
Function Internals......Page 114
Function Parameters......Page 115
Passing Parameters by Reference......Page 117
Returning Values......Page 119
Scoping Rules......Page 120
Filters......Page 123
Implementing New Control Structures......Page 127
Script Blocks as Strategies......Page 130
Summary......Page 132
Working with Aliases......Page 133
Get-Alias......Page 134
The Alias Provider......Page 135
Modifying Aliases......Page 136
Exporting and Importing Aliases......Page 137
Name Clashes......Page 141
Complex Aliases......Page 143
Removing Broken Aliases......Page 144
Built-in Aliases......Page 145
cmd.exe Look-alikes......Page 146
UNIX Look-alikes......Page 147
Convenience Aliases......Page 149
Summary......Page 151
Enumerating Providers......Page 153
Drives......Page 155
Drive Scope......Page 157
Navigating to Drives......Page 158
Item Providers......Page 160
Item Container Providers......Page 161
Item Property Providers......Page 162
Summary......Page 163
Creating Scripts......Page 165
Invoking Scripts......Page 166
Passing Parameters......Page 168
Returning Values......Page 172
Executing PowerShell Scripts from Other Environments......Page 174
Developing and Maintaining Script Libraries......Page 175
The Library Path Problem......Page 176
Summary......Page 180
Handling Errors......Page 181
Common Error-Handling Parameters......Page 183
Trapping Errors......Page 186
Suppressing Errors and Raising Them Again......Page 187
Catching Unknown Errors or All Errors......Page 189
Errors That Cannot Be Trapped......Page 195
Capturing Nonterminating Errors......Page 196
Raising Terminating Errors......Page 198
Raising Nonterminating Errors......Page 201
Debugging Your Code......Page 203
Print Debugging......Page 204
Generating Verbose Output......Page 206
Generating Debug Output......Page 209
Generating Warnings......Page 212
Controlling Error Output......Page 213
Stepping Through Scripts and Breaking Execution......Page 214
Simulating Breakpoints......Page 215
Tracing Intrinsic Shell Operations......Page 216
Operation-Specific Tracing......Page 219
Summary......Page 222
How Code Signing Works......Page 223
Certifying the Origin of a Script......Page 224
Managing Certificates......Page 225
Creating a Certification Authority Certificate......Page 228
Issuing a Code-Signing Certificate......Page 232
Signing Scripts......Page 237
Running Scripts on Other Machines......Page 241
Summary......Page 243
Shell Hosts......Page 245
Settings for All Users and All Shells......Page 249
Settings for a Specific User and a Specific Shell......Page 250
Working with Saved Console Settings......Page 252
Changing the Prompt Settings......Page 254
Tab Expansion: How Command Completion Works......Page 257
Summary......Page 261
Modifying Objects and Types......Page 263
Adding Members to Single Objects......Page 264
Creating New Objects......Page 266
Adding Members to All Instances of a Class......Page 270
Extending Object Formatting......Page 273
Creating Our Own Views......Page 275
Summary......Page 278
The Help System......Page 279
The Basics......Page 280
Parameter Details......Page 282
Advanced Techniques......Page 284
Getting Command Information......Page 290
Getting Information About Objects......Page 292
Using the Internet to Get Help......Page 294
Summary......Page 299
Working with Processes......Page 301
Listing Processes: Getting the Big Picture......Page 302
Starting and Stopping Processes......Page 303
Processes and Their Windows......Page 304
Process Modules: On What Libraries Does This Baby Depend?......Page 305
Setting Process Priority......Page 306
Administering Services......Page 307
Starting and Stopping Services......Page 308
Analyzing Service Dependencies......Page 309
Summary......Page 310
Reading Content......Page 311
Writing Content......Page 314
Content Encoding......Page 315
Getting Byte Content......Page 316
Different Unicode Encodings......Page 317
Finding Matches for a Regular Expression......Page 320
Finding String Occurrences Inside Files......Page 321
Summary......Page 322
Working with the Windows Event Log......Page 323
Reading from the System Event Logs......Page 324
Accessing Remote Event Logs......Page 327
Writing to the Event Log......Page 328
Performance Counters......Page 332
Consuming Counter Data......Page 333
Detecting Memory Leaks......Page 335
Detecting Hung Programs......Page 336
Detecting Unexpected Program Exits......Page 338
Summary......Page 339
Laying the Foundation......Page 341
Fetching Files from the Web......Page 342
Setting Connection Options and Debugging Connection Problems......Page 344
Working with Proxy Servers......Page 345
Working with Request Headers......Page 348
Accessing Resources Requiring Authentication......Page 350
Test-Url: Verifying a Page’s Existence......Page 354
Checking If a Page Contains Broken Links......Page 356
Working with News Feeds......Page 358
Getting Feeds......Page 359
Calling Web Services Using HTTP GET Requests......Page 364
Calling Web Services Using HTTP POST Requests......Page 366
Calling Web Services Using the SOAP Protocol......Page 368
Downloading Files from an FTP Server......Page 371
Uploading Files to an FTP Server......Page 372
Summary......Page 373
Using System.Net.Mail......Page 375
Building a Reusable Script......Page 376
Configuring Recipients......Page 378
Working with Message Headers......Page 381
Message Views......Page 383
Attaching Files to Messages......Page 385
Embedding Media in Messages......Page 387
Putting It All Together......Page 389
Summary......Page 391
Talking to COM Objects......Page 393
How PowerShell Supports COM......Page 394
Automating Microsoft Word......Page 395
Opening Documents and Extracting Text......Page 396
Creating and Modifying Documents......Page 399
Using Microsoft Word’s Spell Checker......Page 402
Getting Help and Going Further......Page 403
Reading Cell Values from a Document......Page 404
Modifying Workbook Content......Page 408
Going Further......Page 409
Scripting a Browser Session......Page 410
Extracting Data from the DOM Tree......Page 413
Windows Script Host Code Interoperability......Page 415
Evaluating Code......Page 416
Exposing Objects from MSScriptControl......Page 418
Summary......Page 419
A Brief History of WMI......Page 421
The Common Information Model......Page 422
Object Discovery......Page 423
PowerShell’s WMI Support......Page 424
Get-WmiObject: The WMI Query Tool......Page 425
Language Support for WMI Objects......Page 427
Getting a List of Classes and Namespaces......Page 430
WMI System Properties......Page 432
Querying Hardware Devices......Page 433
Operating System Updates......Page 434
Installed Programs......Page 435
Generating WMI Code......Page 437
Scriptomatic......Page 438
Summary......Page 440
Installation and Configuration......Page 443
Editing Configuration Files......Page 444
Getting Help......Page 445
Navigation Helpers......Page 447
NTFS Helpers......Page 448
Compressing and Archiving Files......Page 450
Network Utilities......Page 451
Executing Processes and Commands......Page 453
XML Tools......Page 456
Working with Image Files......Page 461
Clipboard Helpers......Page 463
Reading from the .NET Global Assembly Cache......Page 466
Exploiting the Internet Explorer Feed Store......Page 467
Manipulating Windows Active Directory......Page 469
Utility Applications......Page 472
Summary......Page 474
Introducing PSEventing......Page 475
Event-Handling Mechanics......Page 476
FileSystemWatcher: A Real-World Example......Page 477
Monitoring Entries Written to the System Event Logs......Page 478
Handling WMI Events......Page 480
Detecting If Our Script Has Been Terminated by the User......Page 482
Using Script Blocks As Event Handlers......Page 483
Summary......Page 485
Enhancing Tab Completion with PowerTab......Page 487
Installation......Page 488
How PowerTab Works......Page 489
Data Grid Pop-up Windows......Page 492
Configuring PowerTab......Page 493
The IntelliSense Completion Handler......Page 494
The Tab Expansion Database......Page 496
Summary......Page 497
Index......Page 499

Pro Windows PowerShell
 9781590599402, 1590599403, 9781430205463, 1430205466, 9781590599

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Recommend Papers