You are not signed in. Sign in.

List Books: Buy books on ListBooks.org

Microsoft Windows Powershell Programming for the Absolute Beginner » (1st Edition)

Book cover image of Microsoft Windows Powershell Programming for the Absolute Beginner by Jerry Lee Ford Jr.

Authors: Jerry Lee Ford Jr.
ISBN-13: 9781598633542, ISBN-10: 1598633546
Format: Paperback
Publisher: Cengage Learning
Date Published: December 2006
Edition: 1st Edition

Find Best Prices for This Book »

Author Biography: Jerry Lee Ford Jr.

Jerry Lee Ford, Jr. is an author, educator, and an IT professional with more than 18 years of experience in information technology, including roles as an automation analyst, technical manager, technical support analyst, automation engineer, and security analyst. Jerry has a master's degree in business administration from Virginia Commonwealth University in Richmond, Virginia. He is the author of 22 other books and co-author of 2 additional books. His published works include AppleScript Studio Programming for the Absolute Beginner, Microsoft Windows Shell Scripting for the Absolute Beginner, Perl Programming for the Absolute Beginner, Beginning REALbasic, Microsoft Windows Shell Scripting and WSH Administrator's Guide, VBScript Professional Projects, and Microsoft Visual Basic 2005 Express Edition Programming for the Absolute Beginner. He has more than five years of experience as an adjunct instructor teaching networking courses in information technology. Jerry lives in Richmond, Virginia, with his wife, Mary, and their children, William, Alexander,and Molly.

Book Synopsis

Microsoft has finally answered the prayers of system administrators and developers everywhere through the introduction of Windows PowerShell, a new scripting technology that enables the automation of system management tasks and the creation of system management tools. PowerShell runs on Windows XP, 2003, and Vista. Exchange Server 2007 and System Center Operations Manager 2007 will be built on Windows PowerShell. Unlike traditional Windows shell scripting, PowerShell scripting is object based and is designed to work with the .NET framework. Microsoft Windows PowerShell Programming for the Absolute Beginner teaches readers how to program using Microsoft's new PowerShell scripting language through the creation of computer games. No prior knowledge of programming in any language is required. Topics covered include the Windows PowerShell Command Line, object based scripting with .NET, writing PowerShell Scripts, working with variables, arrays and hashes, implementing conditional logic, using loops to process data, organizing scripts using functions, basic system administration, and much more.

Table of Contents


Introduction     xiii
Introducing Windows Powershell     3
Project Preview: The Knock Knock Joke Game     4
Getting to Know Windows PowerShell     7
A Little History Lesson     7
Integration with .NET     8
PowerShell Versus cmd.exe     9
Installing and Configuring Windows PowerShell     10
Interacting with the PowerShell Command Prompt     12
Starting a New PowerShell Session     13
Executing PowerShell Cmdlets     13
Other Types of Commands     16
A Short PowerShell Workout     16
Windows PowerShell Scripting     20
Simplifying PowerShell Script Execution     20
Back to the Knock Knock Joke Game     22
Designing the Game     22
The Final Result     26
Summary     28
Interacting with the Windows PowerShell Command Line     31
Project Preview: The Story of the Three Amigos     32
Accessing Windows PowerShell     35
Customizing the Windows PowerShell Working Environment     36
Customizing Windows PowerShell Shortcuts     36
Configuring the Windows Command Console     38
Windows Command ConsoleCustomization Options     38
Windows Command Console Editing Features     43
Windows PowerShell Edit Enhancements     44
Tab Completion     44
The Get-History Cmdlet     46
Navigating Hierarchical Data Stores     47
Back to The Story of the Three Amigos     52
Creating a New Script     53
Declaring Script Variables     54
Displaying the Introduction     54
Providing Player Instructions     55
Prompting the Player for Input     56
Collecting Additional Inputs     57
Displaying the Story's Opening     58
Displaying the Rest of the Story     59
Summary     62
Object-Based Scripting with.NET     63
Project Preview: The PowerShell Fortune Teller Game     64
One Last PowerShell Customization Technique     66
The Microsoft .NET Framework     68
Key .NET Framework Components     69
The .NET Class Library     69
The Common Language Runtime     70
Accessing .NET Framework Resources     70
Executing Cmdlets     75
Windows PowerShell Plumbing     81
Working with Aliases      84
Back to the PowerShell Fortune Teller Game     87
Designing the Game     87
Creating a New PowerShell Script     88
Declaring and Initializing Variables     88
Displaying the Welcome Screen     89
Displaying Game Instructions     90
Controlling Gameplay     91
Displaying the Closing Screen     93
Summary     94
Working with Variables, Arrays, and Hashes     99
Project Preview: The Seinfeld Trivia Quiz     100
Windows PowerShell Language Features     102
Windows PowerShell Reserved Words     102
Escape Characters     103
String Manipulation     105
Storing and Retrieving Data     107
Variables     107
Arrays     114
Associative Arrays     118
Back to the Seinfeld Trivia Quiz     121
Designing the Game     121
The Final Result     131
Summary     131
Implementing Conditional Logic     133
Project Preview: The Guess My Number Game     134
Comparing Values     136
Combining Pipelines and Operators     137
Implementing Conditional Logic      138
Comparing Data Using the if Statement     139
Making Multiple Comparisons Using the switch Statement     144
Windows PowerShell Operators     146
Comparison Operators     146
Logical Operators     147
String Comparison Operators     148
Back to the Guess My Number Game     150
Designing the Game     150
The Final Result     157
Summary     162
Using Loops to Process Data     163
Project Preview: The Rock, Paper, Scissors Game     164
Working with Loops     166
Setting Up do while Loops     167
Setting Up do until Loops     168
Creating for Loops     169
Creating foreach Loops     172
Using while Loops     175
Altering Loop Execution     176
Using the break Command     176
Using the continue Command     177
Back to the Rock, Paper, Scissors Game     178
Designing the Game     179
The Final Result     188
Summary     188
Organizing Scripts Using Functions     191
Project Preview: The PowerShell Hangman Game     192
Changing Script Design Using Functions and Filters     194
Improving Script Organization     195
Creating Reusable Code     195
Enhancing Script Organization with Functions     196
Function Structure     196
Processing Arguments     198
Processing Incoming Data     203
Returning a Result     204
Restricting Variable Scope     205
Replacing Functions with Filters     207
Back to the PowerShell Hangman Game     208
Creating a New Script     209
Defining and Initializing Script-Level Variables     209
Defining Custom Functions     210
Prompting the Player to Start the Game     212
Setting Up a Loop to Control Gameplay     213
Selecting a Secret Word     213
Setting Up a Loop to Process User Guesses     214
Collecting and Validating User Input     214
Displaying the Results of Each Guess     216
Determining When the Game Is Over     217
Challenging the Player to Play Another Game     219
Summary     220
Working with Files and Folders     225
Project Preview: The PowerShell Tic-Tac-Toe Game     226
Using the Power of Regular Expressions     228
Matching Simple Patterns     228
Matching Alternative Patterns     229
Working with Regular Expression Characters     229
Working with Quantifiers     231
Matching Patterns Based on Ranges     231
Administering Files and Folders     233
Verifying File and Folder Existence     233
Retrieving File and Folder Information     234
Copying and Moving Files and Folders     235
Deleting Files and Folders     236
Renaming Files and Folders     237
Searching Files     237
Reading from and Writing to Files     238
Creating Files and Folders     238
Writing to Text Files     239
Reformatting Cmdlet Output     240
Reading from Text Files     244
Erasing File Contents     245
Saving Data Output as HTML     245
Saving Data as an XML File     245
Reading Data from an XML File     247
Saving Data in a Comma-Separated Value File     247
Reading Data from a Comma-Separated Value File     248
Sending Output to the Printer     249
Back to the PowerShell Tic-Tac-Toe Game      250
Designing the Game     250
The Final Result     263
Summary     264
Basic System Administration     265
Project Preview: The PowerShell Blackjack Game     266
Accessing and Administering System Resources     268
Listing and Stopping Processes     268
Administering Windows Services     269
Accessing Event Logs     274
Retrieving System Information Using WMI     276
Taking Advantage of .NET Classes     281
Taking Advantage of COM Objects     281
Programmatically Interacting with the Windows Registry     284
Back to the PowerShell Blackjack Game     288
Creating a New Script File     288
Defining and Creating New Variables     289
Creating the Get-Permission Function     289
Creating the Check-Registry Function     291
Creating the Play-Game Function     292
Creating the Deal-Hand Function     292
Creating the Get-Card Function     293
Creating the Get-ComputerHand Function     293
Creating the Analyze-Results Function     294
Creating the Get-PlayerHand Function     295
Creating the Get-NewCard Function      297
Adding Controlling Logic to the Main Processing Section     297
Summary     298
Debugging PowerShell Scripts     301
Project Preview: The PowerShell Game Console     302
Understanding PowerShell Errors     303
Syntax Errors     303
Runtime Errors     304
Logical Errors     305
Terminating Versus Non-Terminating Errors     306
Dissecting the Structure of Error Messages     306
Telling Windows PowerShell How to React to Errors     307
Creating Trap Handlers     308
Tracing Script Execution     311
Displaying Output Status Information and Tracking Variable Values     311
Using PowerShell's Debug Mode     313
Back to the PowerShell Game Console     316
Designing the Game     316
The Final Result     322
Summary     322
What's on the Companion Website?     325
What Next?     327
Windows PowerShell IDEs     328
Recommended Reading     329
Locating Microsoft PowerShell Resources Online     330
PowerShell Websites     331
Windows PowerShell News Group     332
PowerShell Blogs      333
The Author's Website     334
Glossary     335
Index     345

Subjects