Windows PowerShell Cookbook - Lee Holmes

Windows PowerShell Cookbook

The Complete Guide to Scripting Microsoft's Command Shell

(Autor)

Buch | Softcover
1036 Seiten
2013 | 3 Rev ed
O'Reilly Media, Inc, USA (Verlag)
978-1-4493-2068-3 (ISBN)
62,80 inkl. MwSt
  • Titel ist leider vergriffen;
    keine Neuauflage
  • Artikel merken
This introduction to the PowerShell language and scripting environment provides more than 400 task-oriented recipes to help you solve the most complex and pressing problems, and includes more than 100 tried-and-tested scripts that intermediate to advanced system administrators can copy and use immediately.
How do you use Windows PowerShell to navigate the filesystem, manage files and folders, or retrieve a web page? This introduction to the PowerShell language and scripting environment provides more than 400 task-oriented recipes to help you solve all kinds of problems. Intermediate to advanced system administrators will find more than 100 tried-and-tested scripts they can copy and use immediately.

Updated for PowerShell 3.0, this comprehensive cookbook includes hands-on recipes for common tasks and administrative jobs that you can apply whether you’re on the client or server version of Windows. You also get quick references to technologies used in conjunction with PowerShell, including format specifiers and frequently referenced registry keys to selected .NET, COM, and WMI classes.
  • Learn how to use PowerShell on Windows 8 and Windows Server 2012
  • Tour PowerShell’s core features, including the command model, object-based pipeline, and ubiquitous scripting
  • Master fundamentals such as the interactive shell, pipeline, and object concepts
  • Perform common tasks that involve working with files, Internet-connected scripts, user interaction, and more
  • Solve tasks in systems and enterprise management, such as working with Active Directory and the filesystem

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 enables him to integrate both the 'how' and the 'why' into discussions. Lee's involvement 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.

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
Resolve Errors Calling Native Executables
Supply Default Values for Parameters
Invoke a Long-Running or Background Command
Program: Monitor a Command for Changes
Notify Yourself of Job Completion
Customize Your Shell, Profile, and Prompt
Customize PowerShell’s User Input Behavior
Customize PowerShell’s Command Resolution Behavior
Find a Command to Accomplish a Task
Get Help on a Command
Update System Help Content
Program: Search Help for Text
Launch PowerShell at a Specific Location
Invoke a PowerShell Command or Script from Outside PowerShell
Understand and Customize PowerShell’s Tab Completion
Program: Learn Aliases for Common Commands
Program: Learn Aliases for Common Parameters
Access and Manage Your Console History
Program: Create Scripts from Your Session History
Invoke a Command from Your Session History
Program: Search Formatted Output for a Pattern
Interactively View and Process Command Output
Program: Interactively View and Explore Objects
Store the Output of a Command into a File
Add Information to the End of a File
Record a Transcript of Your Shell Session
Extend Your Shell with Additional Commands
Use Commands from Customized Shells
Save State Between Sessions
Chapter 2 Pipelines
Introduction
Filter Items in a List or Command Output
Group and Pivot Data by Name
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
Program: Simplify Most Foreach-Object Pipelines
Intercept Stages of the Pipeline
Automatically Capture Pipeline Output
Capture and Redirect Binary Process Output
Chapter 3 Variables and Objects
Introduction
Display the Properties of an Item as a List
Display the Properties of an Item as a Table
Store Information in Variables
Access Environment Variables
Program: Retain Changes to Environment Variables Set by a Batch File
Control Access and Scope of Variables and Other Items
Program: Create a Dynamic Variable
Work with .NET Objects
Create an Instance of a .NET Object
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
Create and Initialize Custom Objects
Add Custom Methods and Properties to Types
Define Custom Formatting for a Type
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
Split a String on Text or a Pattern
Combine Strings into a Larger String
Convert a String to Uppercase or Lowercase
Trim a String
Format a Date for Output
Program: Convert Text Streams to Objects
Generate Large Reports and Text Streams
Generate Source Code and Other Repetitive Text
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
Chapter 7 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
Compare Two Lists
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 8 Utility Tasks
Introduction
Get the System Date and Time
Measure the Duration of a Command
Read and Write from the Windows Clipboard
Generate a Random Number or Object
Program: Search the Windows Start Menu
Program: Show Colorized Script Content
Common Tasks
Chapter 9 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
Program: Get the Encoding of a File
Program: View the Hexadecimal Representation of Content
Chapter 10 Structured Files
Introduction
Access Information in an XML File
Perform an XPath Query Against XML
Convert Objects to XML
Modify Data in an XML File
Easily Import and Export Your Structured Data
Store the Output of a Command in a CSV or Delimited File
Import CSV and Delimited Data from a File
Manage JSON Data Streams
Use Excel to Manage Command Output
Parse and Interpret PowerShell Scripts
Chapter 11 Code Reuse
Introduction
Write a Script
Write a Function
Find a Verb Appropriate for a Command Name
Write a Script Block
Return Data from a Script, Function, or Script Block
Package Common Commands in a Module
Write Commands That Maintain State
Selectively Export Commands from a Module
Diagnose and Interact with Internal Module State
Handle Cleanup Tasks When a Module Is Removed
Access Arguments of a Script, Function, or Script Block
Add Validation to Parameters
Accept Script Block Parameters with Local Variables
Dynamically Compose Command Parameters
Provide -WhatIf, -Confirm, and Other Cmdlet Features
Add Help to Scripts or Functions
Add Custom Tags to a Function or Script Block
Access Pipeline Input
Write Pipeline-Oriented Scripts with Cmdlet Keywords
Write a Pipeline-Oriented Function
Organize Scripts for Improved Readability
Invoke Dynamically Named Commands
Program: Enhance or Extend an Existing Cmdlet
Chapter 12 Internet-Enabled Scripts
Introduction
Download a File from an FTP or Internet Site
Upload a File to an FTP Site
Download a Web Page from the Internet
Parse and Analyze a Web Page from the Internet
Script a Web Application Session
Program: Get-PageUrls
Interact with REST-Based Web APIs
Connect to a Web Service
Export Command Output as a Web Page
Send an Email
Program: Monitor Website Uptimes
Program: Interact with Internet Protocols
Chapter 13 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
Support Other Languages in Script Output
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
Interact with MTA Objects
Chapter 14 Debugging
Introduction
Prevent Common Scripting Errors
Trace Script Execution
Set a Script Breakpoint
Debug a Script When It Encounters an Error
Create a Conditional Breakpoint
Investigate System State While Debugging
Program: Watch an Expression for Changes
Program: Get Script Code Coverage
Chapter 15 Tracing and Error Management
Introduction
Determine the Status of the Last Command
View the Errors Generated by a Command
Manage the Error Output of Commands
Program: Resolve an Error
Configure Debug, Verbose, and Progress Output
Handle Warnings, Errors, and Terminating Errors
Output Warnings, Errors, and Terminating Errors
Program: Analyze a Script’s Performance Profile
Chapter 16 Environmental Awareness
Introduction
View and Modify Environment Variables
Modify the User or System Path
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
Get the Current Location
Safely Build File Paths Out of Their Components
Interact with PowerShell’s Global Environment
Determine PowerShell Version Information
Test for Administrative Privileges
Chapter 17 Extend the Reach of Windows PowerShell
Introduction
Automate Programs Using COM Scripting Interfaces
Program: Query a SQL Data Source
Access Windows Performance Counters
Access Windows API Functions
Program: Invoke Simple Windows API Calls
Define or Extend a .NET Class
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 18 Security and Script Signing
Introduction
Enable Scripting Through an Execution Policy
Disable Warnings for UNC Paths
Sign a PowerShell Script, Module, or Formatting File
Program: Create a Self-Signed Certificate
Manage PowerShell Security in an Enterprise
Block Scripts by Publisher, Path, or Hash
Verify the Digital Signature of a PowerShell Script
Securely Handle Sensitive Information
Securely Request Usernames and Passwords
Program: Start a Process as Another User
Program: Run a Temporarily Elevated Command
Securely Store Credentials on Disk
Access User and Machine Certificates
Program: Search the Certificate Store
Add and Remove Certificates
Manage Security Descriptors in SDDL Form
Chapter 19 Integrated Scripting Environment
Introduction
Debug a Script
Customize Text and User Interface Colors
Connect to a Remote Computer
Extend ISE Functionality Through Its Object Model
Quickly Insert Script Snippets
Add an Item to the Tools Menu
Administrator Tasks
Chapter 20 Files and Directories
Introduction
Determine the Current Location
Get the Files in a Directory
Find All Files Modified Before a Certain Date
Clear the Content of a File
Manage and Change the Attributes of a File
Find Files That Match a Pattern
Manage Files That Include Special Characters
Program: Get Disk Usage Information
Monitor a File for Changes
Get the Version of a DLL or Executable
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
Create and Map PowerShell Drives
Access Long File and Directory Names
Unblock a File
Interact with Alternate Data Streams
Program: Move or Remove a Locked File
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 21 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
Safely Combine Related Registry Modifications
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 22 Comparing Data
Introduction
Compare the Output of Two Commands
Determine the Differences Between Two Files
Verify Integrity of File Sets
Chapter 23 Event Logs
Introduction
List All Event Logs
Get the Newest Entries from an Event Log
Find Event Log Entries with Specific Text
Retrieve and Filter Event Log Entries
Find Event Log Entries by Their Frequency
Back Up an Event Log
Create or Remove an Event Log
Write to an Event Log
Run a PowerShell Script for Windows Event Log Entries
Clear or Maintain an Event Log
Access Event Logs of a Remote Machine
Chapter 24 Processes
Introduction
List Currently Running Processes
Launch the Application Associated with a Document
Launch a Process
Stop a Process
Get the Owner of a Process
Get the Parent Process of a Process
Debug a Process
Chapter 25 System Services
Introduction
List All Running Services
Manage a Running Service
Configure a Service
Chapter 26 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
Delete an Organizational Unit
Get the Children of an Active Directory Container
Create a User Account
Program: Import Users in Bulk to Active Directory
Search for a User Account
Get and List the Properties of a User Account
Modify Properties of a User Account
Change a User Password
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 27 Enterprise Computer Management
Introduction
Join a Computer to a Domain or Workgroup
Remove a Computer from a Domain
Rename a Computer
Program: List Logon or Logoff Scripts for a User
Program: List Startup or Shutdown Scripts for a Machine
Deploy PowerShell-Based Logon Scripts
Enable or Disable the Windows Firewall
Open or Close Ports in the Windows Firewall
Program: List All Installed Software
Uninstall an Application
Manage Computer Restore Points
Reboot or Shut Down a Computer
Determine Whether a Hotfix Is Installed
Manage Scheduled Tasks on a Computer
Retrieve Printer Information
Retrieve Printer Queue Statistics
Manage Printers and Print Queues
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 28 Windows Management Instrumentation
Introduction
Access Windows Management Instrumentation and CIM Data
Modify the Properties of a WMI or CIM Instance
Invoke a Method on a WMI Instance or Class
Program: Determine Properties Available to WMI and CIM Filters
Program: Search for WMI Classes
Use .NET to Perform Advanced WMI Tasks
Improve the Performance of Large-Scale WMI Operations
Convert a VBScript WMI Script to PowerShell
Chapter 29 Remoting
Introduction
Find Commands That Support Their Own Remoting
Enable PowerShell Remoting on a Computer
Interactively Manage a Remote Computer
Invoke a Command on a Remote Computer
Disconnect and Reconnect PowerShell Sessions
Program: Remotely Enable PowerShell Remoting
Program: Invoke a PowerShell Expression on a Remote Machine
Test Connectivity Between Two Computers
Limit Networking Scripts to Hosts That Respond
Enable Remote Desktop on a Computer
Configure User Permissions for Remoting
Enable Remoting to Workgroup Computers
Implicitly Invoke Commands from a Remote Computer
Create Sessions with Full Network Access
Pass Variables to Remote Sessions
Configure Advanced Remoting Quotas and Options
Invoke a Command on Many Computers
Run a Local Script on a Remote Computer
Program: Transfer a File to a Remote Computer
Determine Whether a Script Is Running on a Remote Computer
Create a Task-Specific Remoting Endpoint
Chapter 30 Workflows
Introduction
Write a Workflow
Run a Workflow
Suspend and Resume a Workflow
Invoke Islands of Traditional PowerShell Script
Invoke Workflow Actions in Parallel
Customize an Activity’s Connection Parameters
Write a Workflow That Requires Human Intervention
Add Raw XAML to a Workflow
Reference Custom Activities in a Workflow
Debug or Troubleshoot a Workflow
Use PowerShell Activities from a Traditional Windows Workflow Application
Chapter 31 Transactions
Introduction
Safely Experiment with Transactions
Change Error Recovery Behavior in Transactions
Chapter 32 Event Handling
Introduction
Respond to Automatically Generated Events
Create and Respond to Custom Events
Create a Temporary Event Subscription
Forward Events from a Remote Computer
Investigate Internal Event Action State
Use a Script Block as a .NET Delegate or Event Handler
References
Appendix PowerShell Language and Environment
Commands and Expressions
Comments
Help 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
Common Customization Points
Appendix Regular Expression Reference
Appendix XPath Quick Reference
Appendix .NET String Formatting
String Formatting Syntax
Standard Numeric Format Strings
Custom Numeric Format Strings
Appendix .NET DateTime Formatting
Custom DateTime Format Strings
Appendix Selected .NET Classes and Their Uses
Appendix WMI Reference
Appendix Selected COM Objects and Their Uses
Appendix Selected Events and Their Uses
Appendix Standard PowerShell Verbs
Colophon

Erscheint lt. Verlag 8.1.2013
Verlagsort Sebastopol
Sprache englisch
Maße 178 x 233 mm
Gewicht 1592 g
Einbandart Paperback
Themenwelt Informatik Betriebssysteme / Server Windows Server
Informatik Programmiersprachen / -werkzeuge NET Programmierung
Mathematik / Informatik Informatik Software Entwicklung
ISBN-10 1-4493-2068-6 / 1449320686
ISBN-13 978-1-4493-2068-3 / 9781449320683
Zustand Neuware
Haben Sie eine Frage zum Produkt?
Mehr entdecken
aus dem Bereich
Das umfassende Handbuch für Administratoren

von Markus Widl

Buch | Hardcover (2022)
Rheinwerk (Verlag)
69,90