Publisher: O'Reilly Media
Final Release Date: October 2007
Pages: 592
This Cookbook by Windows PowerShell team developer Lee Holmes provides hundreds of tested scripts that you can use right away to get Microsoft's new tool working for you. More than 150 recipes, combined with a concise task-based introduction to the Windows PowerShell scripting language and environment, make it the perfect look-up guide when you encounter a thorny problem, or need a quick solution. The ideal companion to any tutorial or reference, this book meets the needs of system administrators at any level.
Microsoft has revolutionized the world of system management and command-line shells with its release of Windows PowerShell, and Lee Holmes gives you practical tools and inside advice that will make you a more productive user and administrator. You will be able to solve everything from automating routine tasks, working with files, event logs and other forms of structured data, to managing the users and resources of complex Windows networks. Each recipe includes a focused piece of code plus discussion of how and why it works, so that you can apply the solution to similar tasks.
You get an array of recipes covering PowerShell fundamentals, common tasks, and administrator tasks, including:
- Pipelines, variables, objects, looping and flow control, strings and unstructured text, calculations and math
- Simple files; structured files; Internet-enabled scripts; code reuse; lists, arrays and hashtables; user feedback; error management; environmental awareness; script signing; and more
- Files and directories, registry manipulation, comparing data, event logs, process cmdlets, service cmdlets, Active Directory, enterprise computer management, and more
Those who administer Microsoft's Exchange 2007 and System Center Operations Manager (formerly MOM) will also benefit from this book, with separate chapters devoted to these servers. All Windows administrators will appreciate the appendices that include a PowerShell language quick reference, and a reference to the .NET, WMI and COM objects that PowerShell scripters will use often.
With working scripts, tutorials, and references all in one volume, Windows PowerShell Cookbook will turbocharge the productivity of any Windows administrator.
|
-
Tour -
A Guided Tour of Windows PowerShell - Introduction
- An Interactive Shell
- Structured Commands (Cmdlets)
- Deep Integration of Objects
- Administrators As First-Class Users
- Composable Commands
- Techniques to Protect You from Yourself
- Common Discovery Commands
- Ubiquitous Scripting
- Ad Hoc Development
- Bridging Technologies
- Namespace Navigation Through Providers
- Much, Much More
-
Fundamentals -
Chapter 1 The Windows PowerShell Interactive Shell - Introduction
- Run Programs, Scripts, and Existing Tools
- Run a PowerShell Command
- Customize Your Shell, Profile, and Prompt
- Find a Command to Accomplish a Task
- Get Help on a Command
- Program: Search Help for Text
- Invoke a PowerShell Script From Outside PowerShell
- Program: Retain Changes to Environment Variables Set by a Batch File
- Get the System Date and Time
- Determine the Status of the Last Command
- Measure the Duration of a Command
- Customize the Shell to Improve Your Productivity
- Program: Learn Aliases for Common Commands
- Access and Manage Your Console History
- Store the Output of a Command into a File
- Add Information to the End of a File
- Record a Transcript of Your Shell Session
- Display the Properties of an Item As a List
- Display the Properties of an Item As a Table
- Manage the Error Output of Commands
- Configure Debug, Verbose, and Progress Output
- Extend Your Shell with Additional Snapins
- Use Console Files to Load and Save Sets of Snapins
-
Chapter 2 Pipelines - Introduction
- Filter Items in a List or Command Output
- Program: Simplify Most Where-Object Filters
- Program: Interactively Filter Lists of Objects
- Work with Each Item in a List or Command Output
- Automate Data-Intensive Tasks
-
Chapter 3 Variables and Objects - Introduction
- Store Information in Variables
- Access Environment Variables
- Control Access and Scope of Variables and Other Items
- Work with .NET Objects
- Create an Instance of a .NET Object
- Program: Create Instances of Generic Objects
- Reduce Typing for Long Class Names
- Use a COM Object
- Learn About Types and Objects
- Get Detailed Documentation About Types and Objects
- Add Custom Methods and Properties to Objects
- Add Custom Methods and Properties to Types
-
Chapter 4 Looping and Flow Control - Introduction
- Make Decisions with Comparison and Logical Operators
- Adjust Script Flow Using Conditional Statements
- Manage Large Conditional Statements with Switches
- Repeat Operations with Loops
- Add a Pause or Delay
-
Chapter 5 Strings and Unstructured Text - Introduction
- Create a String
- Create a Multiline or Formatted String
- Place Special Characters in a String
- Insert Dynamic Information in a String
- Prevent a String from Including Dynamic Information
- Place Formatted Information in a String
- Search a String for Text or a Pattern
- Replace Text in a String
- Convert a String to Upper/Lowercase
- Trim a String
- Format a Date for Output
- Program: Convert Text Streams to Objects
- Generate Large Reports and Text Streams
-
Chapter 6 Calculations and Math - Introduction
- Perform Simple Arithmetic
- Perform Complex Arithmetic
- Measure Statistical Properties of a List
- Work with Numbers As Binary
- Simplify Math with Administrative Constants
- Convert Numbers Between Bases
-
Common Tasks -
Chapter 7 Simple Files - Introduction
- Get the Content of a File
- Search a File for Text or a Pattern
- Parse and Manage Text-Based Logfiles
- Parse and Manage Binary Files
- Create a Temporary File
- Search and Replace Text in a File
-
Chapter 8 Structured Files - Introduction
- Access Information in an XML File
- Perform an XPath Query Against an XML File
- Modify Data in an XML File
- Easily Import and Export Your Structured Data
- Store the Output of a Command in a CSV File
- Import Structured Data from a CSV File
- Use Excel to Manage Command Output
-
Chapter 9 Internet-Enabled Scripts - Introduction
- Download a File from the Internet
- Download a Web Page from the Internet
- Program: Get-PageUrls
- Program: Connect-WebService
- Export Command Output As a Web Page
- Program: Send an Email
- Program: Interact with Internet Protocols
-
Chapter 10 Code Reuse - Introduction
- Write a Script
- Write a Function
- Write a Script Block
- Return Data from a Script, Function, or Script Block
- Place Common Functions in a Library
- Access Arguments of a Script, Function, or Script Block
- Access Pipeline Input
- Write Pipeline-Oriented Scripts with Cmdlet Keywords
- Write a Pipeline-Oriented Function
-
Chapter 11 Lists, Arrays, and Hashtables - Introduction
- Create an Array or List of Items
- Create a Jagged or Multidimensional Array
- Access Elements of an Array
- Visit Each Element of an Array
- Sort an Array or List of Items
- Determine Whether an Array Contains an Item
- Combine Two Arrays
- Find Items in an Array That Match a Value
- Remove Elements from an Array
- Find Items in an Array Greater or Less Than a Value
- Use the ArrayList Class for Advanced Array Tasks
- Create a Hashtable or Associative Array
- Sort a Hashtable by Key or Value
-
Chapter 12 User Interaction - Introduction
- Read a Line of User Input
- Read a Key of User Input
- Program: Display a Menu to the User
- Display Messages and Output to the User
- Provide Progress Updates on Long-Running Tasks
- Write Culture-Aware Scripts
- Program: Invoke a Script Block with Alternate Culture Settings
- Access Features of the Host's User Interface
- Program: Add a Graphical User Interface to Your Script
-
Chapter 13 Tracing and Error Management - Introduction
- View the Errors Generated by a Command
- Handle Warnings, Errors, and Terminating Errors
- Output Warnings, Errors, and Terminating Errors
- Debug a Script
- Collect Detailed Traces of a Script or Command
- Program: Analyze a Script's Performance Profile
-
Chapter 14 Environmental Awareness - Introduction
- View and Modify Environment Variables
- Access Information About Your Command's Invocation
- Program: Investigate the InvocationInfo Variable
- Find Your Script's Name
- Find Your Script's Location
- Find the Location of Common System Paths
- Program: Search the Windows Start Menu
- Get the Current Location
- Safely Build File Paths Out of Their Components
- Interact with PowerShell's Global Environment
-
Chapter 15 Extend the Reach of Windows PowerShell - Introduction
- Access Windows Management Instrumentation Data
- Program: Determine Properties Available to WMI Filters
- Program: Search for WMI Classes
- Use .NET to Perform Advanced WMI Tasks
- Convert a VBScript WMI Script to PowerShell
- Automate Programs Using COM Scripting Interfaces
- Program: Query a SQL Data Source
- Access Windows Performance Counters
- Program: Invoke Native Windows API Calls
- Program: Add Inline C# to Your PowerShell Script
- Access a .NET SDK Library
- Create Your Own PowerShell Cmdlet
- Add PowerShell Scripting to Your Own Program
-
Chapter 16 Security and Script Signing - Introduction
- Enable Scripting Through an Execution Policy
- Sign a PowerShell Script or Formatting File
- Program: Create a Self-Signed Certificate
- Manage PowerShell Security in an Enterprise
- Verify the Digital Signature of a PowerShell Script
- Securely Handle Sensitive Information
- Securely Request Usernames and Passwords
- Program: Start a Process As Another User
- Securely Store Credentials on Disk
- Access User and Machine Certificates
- Program: Search the Certificate Store
-
Administrator Tasks -
Chapter 17 Files and Directories - Introduction
- Find All Files Modified Before a Certain Date
- Clear or Remove a File
- Manage and Change the Attributes of a File
- Get the Files in a Directory
- Find Files That Match a Pattern
- Manage Files That Include Special Characters
- Program: Get Disk Usage Information
- Determine the Current Location
- Monitor a File for Changes
- Program: Get the MD5 or SHA1 Hash of a File
- Create a Directory
- Remove a File or Directory
- Rename a File or Directory
- Move a File or Directory
- Get the ACL of a File or Directory
- Set the ACL of a File or Directory
- Program: Add Extended File Properties to Files
- Program: Create a Filesystem Hard Link
- Program: Create a ZIP Archive
-
Chapter 18 The Windows Registry - Introduction
- Navigate the Registry
- View a Registry Key
- Modify or Remove a Registry Key Value
- Create a Registry Key Value
- Remove a Registry Key
- Add a Site to an Internet Explorer Security Zone
- Modify Internet Explorer Settings
- Program: Search the Windows Registry
- Get the ACL of a Registry Key
- Set the ACL of a Registry Key
- Work with the Registry of a Remote Computer
- Program: Get Registry Items from Remote Machines
- Program: Get Properties of Remote Registry Keys
- Program: Set Properties of Remote Registry Keys
- Discover Registry Settings for Programs
-
Chapter 19 Comparing Data - Introduction
- Compare the Output of Two Commands
- Determine the Differences Between Two Files
- Verify Integrity of File Sets
-
Chapter 20 Event Logs - Introduction
- List All Event Logs
- Get the Newest Entries from an Event Log
- Find Event Log Entries with Specific Text
- Retrieve a Specific Event Log Entry
- Find Event Log Entries by Their Frequency
- Back Up an Event Log
- Create or Remove an Event Log
- Write to an Event Log
- Access Event Logs of a Remote Machine
-
Chapter 21 Processes - Introduction
- List Currently Running Processes
- Launch a Process
- Stop a Process
- Program: Invoke a PowerShell Expression on a Remote Machine
-
Chapter 22 System Services - Introduction
- List All Running Services
- Manage a Running Service
- Access Services on a Remote Machine
-
Chapter 23 Active Directory - Introduction
- Test Active Directory Scripts on a Local Installation
- Create an Organizational Unit
- Get the Properties of an Organizational Unit
- Modify Properties of an Organizational Unit
- Get the Children of an Active Directory Container
- Create a User Account
- Search for a User Account
- Get and List the Properties of a User Account
- Modify Properties of a User Account
- Create a Security or Distribution Group
- Search for a Security or Distribution Group
- Get the Properties of a Group
- Find the Owner of a Group
- Modify Properties of a Security or Distribution Group
- Add a User to a Security or Distribution Group
- Remove a User from a Security or Distribution Group
- List a User's Group Membership
- List the Members of a Group
- List the Users in an Organizational Unit
- Search for a Computer Account
- Get and List the Properties of a Computer Account
-
Chapter 24 Enterprise Computer Management - Introduction
- Program: List Logon or Logoff Scripts for a User
- Program: List Startup or Shutdown Scripts for a Machine
- Enable or Disable the Windows Firewall
- Open or Close Ports in the Windows Firewall
- Program: List All Installed Software
- Uninstall an Application
- Manage Scheduled Tasks on a Computer
- Retrieve Printer Information
- Retrieve Printer Queue Statistics
- Manage Printers and Print Queues
- Determine Whether a Hotfix Is Installed
- Program: Summarize System Information
- Renew a DHCP Lease
- Assign a Static IP Address
- List All IP Addresses for a Computer
- List Network Adapter Properties
-
Chapter 25 Manage an Exchange 2007 Server - Introduction
- Experiment with Exchange Management Shell
- Automate Wizard-Guided Tasks
- Manage Exchange Users
- Manage Mailboxes
- Manage Distribution Groups
- Manage Transport Rules
- Manage Outlook Web Access
-
Chapter 26 Manage an Operations Manager 2007 Server - Introduction
- Experiment with the Command Shell
- Manage Operations Manager Agents
- Schedule a Maintenance Window
- Get, Install, and Uninstall Management Packs
- Enable or Disable Rules
- List and Start Tasks
- Manage Alerts
-
References -
Appendix PowerShell Language and Environment - Commands and Expressions
- Comments
- Variables
- Booleans
- Strings
- Numbers
- Arrays and Lists
- Hashtables (Associative Arrays)
- XML
- Simple Operators
- Comparison Operators
- Conditional Statements
- Looping Statements
- Working with the .NET Framework
- Writing Scripts, Reusing Functionality
- Managing Errors
- Formatting Output
- Capturing Output
- Tracing and Debugging
- Common Customization Points
-
Appendix Regular Expression Reference -
Appendix PowerShell Automatic Variables -
Appendix Standard PowerShell Verbs -
Appendix Selected .NET Classes and Their Uses -
Appendix WMI Reference -
Appendix Selected COM Objects and Their Uses -
Appendix .NET String Formatting - String Formatting Syntax
- Standard Numeric Format Strings
- Custom Numeric Format Strings
-
Appendix .NET DateTime Formatting - Custom DateTime Format Strings
-
Colophon |
- Title:
- Windows PowerShell Cookbook
- By:
- Lee Holmes
- Publisher:
- O'Reilly Media
- Formats:
-
- Print
- Ebook
- Safari Books Online
- Print:
- October 2007
- Ebook:
- December 2008
- Pages:
- 592
- Print ISBN:
- 978-0-596-52849-2
- | ISBN 10:
- 0-596-52849-3
- Ebook ISBN:
- 978-0-596-15857-6
- | ISBN 10:
- 0-596-15857-2
|
-
Lee Holmes Lee Holmes is a developer on the Microsoft Windows PowerShell team, and has been an authoritative source of information about PowerShell since its earliest betas. His vast experience with Windows PowerShell lets him to integrate both the "how" and the "why" into discussions. Lee's integration with the PowerShell and administration community (via newsgroups, mailing lists, and blogs) gives him a great deal of insight into the problems faced by all levels of administrators, and PowerShell users alike. View Lee Holmes's full profile page. |
Colophon The animal on the cover of Windows PowerShell Cookbook is a box turtle (Terrapenecarolina carolina). This box turtle is native to North America, specifically northernareas in the Unites States and northern parts of Mexico. The average male turtle isabout six inches long and has red eyes; the female is a bit smaller and has yelloweyes. This turtle is omnivorous as a youth but largely herbivorous as an adult. It has a domed shell that is hinged on the bottom and snaps tightly shut if the turtle is indanger (once its head, tail, and limbs are safely inside). Box turtles usually staywithin the same area they were born, rarely leaving a 750 foot radius. During mating rituals, male turtles will sometimes shove and push each other to win the female's attention. During copulation, it is possible for the male turtle to fall backward, be unable to right himself, and starve to death. Although box turtles can live for more than 100 years, their habitats are being seriously threatened by land development and roads. Turtles need loose, humid soil to lay eggs and burrow during their long hibernation season. Box turtles are also highly susceptible to contracting diseases from household pets. Experts strongly discourage taking turtles from their native habitat-not only will it disrupt the community's breeding opportunities, but the turtle will become extremely stressed when outside of its known habitat and perish quickly. |
|
Table of Contents
|
Product Details
|
About the Author
|
Colophon
|
 |
|
 |
|
|
|
Recommended for You
|
 |
|
|
|
Customer Reviews
3/9/2009 (0 of 1 customers found this review helpful) 3/28/2008 (2 of 3 customers found this review helpful) 5.0Currently a must-have PowerShell book. By Anonymous from Undisclosed 1/12/2008 (0 of 1 customers found this review helpful) 5.0PowerShell - one step further down the road
|
|
|