Search and Find
Service
Contents at a Glance
5
Contents
7
About the Author
16
About the Technical Reviewer
17
Acknowledgments
18
Introduction
19
Why Another Book on Windows PowerShell?
19
What’s in This Book?
19
Do I Need Prior Programming Experience?
20
Objects and Object Types
21
The Extended Type System
21
Built- in Types
28
Type Literals
45
Summary
51
Controlling Execution Flow
52
Conditional Expressions
52
Branching Instructions
63
Loops: Repeatedly Executing Blocks of Code
67
Summary
73
The Object Pipeline
74
Text-Based Pipelines
74
Object-Based Pipelines
75
Processing Collections Using ForEach- Object
78
Filtering Collections Using Where-Object
79
Adding or Deleting Properties Using Select-Object
79
Sorting Collections
81
Pipeline Tees
82
Grouping Objects
83
Gathering Collection Statistics
84
Detecting Changes and Differences Among Objects
84
The Object Pipeline and Functional Programming
85
Summary
86
Working with Script Blocks
87
Defining Script Blocks
87
Passing Parameters and Returning Values
89
Processing Pipeline Input
93
Invoking Strings as Expressions
101
Script Blocks as Delegates
103
Summary
104
Working with Functions
105
Defining Functions
105
Filters
115
Functions and Script Blocks
119
Summary
124
Command Aliases
125
Working with Aliases
125
Aliasing Tips, Techniques, and Pitfalls
133
Built- in Aliases
137
Summary
143
Providers
144
Enumerating Providers
144
Drives
146
Navigating to Drives
149
Provider Capabilities
151
Summary
154
Script Files
155
Creating Scripts
155
Executing PowerShell Scripts from Other Environments
164
Developing and Maintaining Script Libraries
165
Summary
170
Error Handling and Debugging
171
Handling Errors
171
Debugging Your Code
193
Summary
212
Signing Scripts
213
How Code Signing Works
213
Managing Certificates
215
Creating a Self- Signed Certificate
218
Signing Scripts
227
Running Scripts on Other Machines
231
Summary
233
The Shell Environment and Its Configuration
234
Shell Hosts
234
User Profile Scripts
238
Working with Saved Console Settings
241
Changing the Prompt Settings
243
Tab Expansion: How Command Completion Works
246
Summary
250
Extending the Type System
252
Modifying Objects and Types
252
Extending Object Formatting
262
Summary
267
Getting Help
268
The Help System
268
Getting Command Information
279
Getting Information About Objects
281
Using the Internet to Get Help
283
Summary
288
Taming Processes and Services
289
Working with Processes
289
Administering Services
295
Summary
298
Input and Output
299
Reading Content
299
Writing Content
302
Content Encoding
303
Extracting Data from Text
308
Summary
310
Monitoring Your System
311
Working with the Windows Event Log
311
Performance Counters
320
Summary
327
PowerShell and the World Wide Web
328
Laying the Foundation
328
Testing and Validating Web Sites
341
Working with News Feeds
345
Calling Web Services
351
Handling FTP Transactions
358
Summary
360
Sending E-mail
361
Using System. Net. Mail
361
Building a Reusable Script
362
Configuring Recipients
364
Working with Message Headers
367
Multipart Messages
369
Putting It All Together
375
Summary
377
Talking to COM Objects
378
How COM Works
379
How PowerShell Supports COM
379
Scripting Programs Through Their COM Interfaces
380
Windows Script Host Code Interoperability
400
Summary
404
Managing Windows with WMI
405
A Brief History of WMI
405
WBEM and WMI Components
406
PowerShell’s WMI Support
408
Language Support for WMI Objects
411
Exploring CIM Classes and Objects
414
Querying Hardware Devices
417
Getting Information About Software
418
The Network Configuration
421
Generating WMI Code
421
Summary
424
PowerShell Community Extensions
426
Installation and Configuration
426
File System Utilities
430
Network Utilities
434
Executing Processes and Commands
436
XML Tools
439
Working with Image Files
444
Clipboard Helpers
446
New Providers
449
Utility Applications
455
Summary
457
PSEventing: .NET Events in PowerShell
458
Introducing PSEventing
458
Event-Handling Mechanics
459
FileSystemWatcher: A Real- World Example
460
Monitoring Entries Written to the System Event Logs
461
Handling WMI Events
463
Detecting If Our Script Has Been Terminated by the User
465
Using Script Blocks As Event Handlers
466
Summary
468
Enhancing Tab Completion with PowerTab
469
Installation
470
How PowerTab Works
471
Configuring PowerTab
475
Summary
479
Index
480
All prices incl. VAT