Home Page Icon
Home Page
Table of Contents for
V. References
Close
V. References
by Lee Holmes
Windows PowerShell Cookbook, 2nd Edition
Windows PowerShell Cookbook
A Note Regarding Supplemental Files
Foreword
Foreword to the First Edition
Glue, Enablers, and a WSH
That Lee Guy
Preface
Who This Book Is For
How This Book Is Organized
Part I
Part II
Part III
Part IV
Part V
What You Need to Use This Book
Conventions Used in This Book
Code Examples
Obtaining Code Examples
Using Code Examples
Comments and Questions
Safari® Books Online
Acknowledgments
I. 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
II. Fundamentals
1. The Windows PowerShell Interactive Shell
Introduction
Run Programs, Scripts, and Existing Tools
Problem
Solution
Discussion
See Also
Resolve Errors Calling Native Executables
Problem
Solution
Discussion
See Also
Run a PowerShell Command
Problem
Solution
Discussion
See Also
Invoke a Long-Running or Background Command
Problem
Solution
Discussion
See Also
Notify Yourself of Job Completion
Problem
Solution
Discussion
See Also
Customize Your Shell, Profile, and Prompt
Problem
Solution
Discussion
See Also
Find a Command to Accomplish a Task
Problem
Solution
Discussion
See Also
Get Help on a Command
Problem
Solution
Discussion
See Also
Program: Search Help for Text
See Also
Program: View PowerShell’s HTML Help
See Also
Launch PowerShell at a Specific Location
Problem
Solution
Discussion
Invoke a PowerShell Command or Script from Outside PowerShell
Problem
Solution
Discussion
See Also
Customize the Shell to Improve Your Productivity
Problem
Solution
Discussion
See Also
Program: Learn Aliases for Common Commands
See Also
Program: Learn Aliases for Common Parameters
Problem
Solution
Discussion
See Also
Access and Manage Your Console History
Problem
Solution
Discussion
See Also
Program: Create Scripts from Session History
See Also
Invoke a Command from Your Session History
Problem
Solution
Discussion
See Also
Program: Search Formatted Output for a Pattern
See Also
Interactively View and Process Command Output
Problem
Solution
Discussion
Processing output
See Also
Store the Output of a Command into a File
Problem
Solution
Discussion
See Also
Add Information to the End of a File
Problem
Solution
Discussion
See Also
Record a Transcript of Your Shell Session
Problem
Solution
Discussion
Extend Your Shell with Additional Commands
Problem
Solution
Discussion
See Also
Use Commands from Customized Shells
Problem
Solution
Discussion
Detecting loaded snapins
Detecting loaded modules
See Also
Save State Between Sessions
Problem
Solution
Discussion
See Also
2. Pipelines
Introduction
Filter Items in a List or Command Output
Problem
Solution
Discussion
See Also
Group and Pivot Data by Name
Problem
Solution
Discussion
See Also
Program: Simplify Most Where-Object Filters
See Also
Program: Interactively Filter Lists of Objects
See Also
Work with Each Item in a List or Command Output
Problem
Solution
Discussion
See Also
Automate Data-Intensive Tasks
Problem
Solution
Discussion
See Also
Program: Simplify Most Foreach-Object Pipelines
Problem
Solution
Discussion
See Also
Intercept Stages of the Pipeline
Problem
Solution
Discussion
See Also
Automatically Capture Pipeline Output
Problem
Solution
Discussion
See Also
Capture and Redirect Binary Process Output
Problem
Solution
Discussion
See Also
3. Variables and Objects
Introduction
Display the Properties of an Item as a List
Problem
Solution
Discussion
Display the Properties of an Item as a Table
Problem
Solution
Discussion
See Also
Store Information in Variables
Problem
Solution
Discussion
See Also
Access Environment Variables
Problem
Solution
Discussion
See Also
Program: Retain Changes to Environment Variables Set by a Batch File
See Also
Control Access and Scope of Variables and Other Items
Problem
Solution
Discussion
Variables
Functions
Aliases and drives
See Also
Program: Create a Dynamic Variable
Work with .NET Objects
Problem
Solution
Discussion
Static methods
Instance methods
Static properties
Instance properties
See Also
Create an Instance of a .NET Object
Problem
Solution
Discussion
Load types from another assembly
See Also
Program: Create Instances of Generic Objects
Reduce Typing for Long Class Names
Problem
Solution
Discussion
See Also
Use a COM Object
Problem
Solution
Discussion
See Also
Learn About Types and Objects
Problem
Solution
Discussion
See Also
Get Detailed Documentation About Types and Objects
Problem
Solution
Discussion
Public constructors
Public fields/public properties
Public methods
See Also
Add Custom Methods and Properties to Objects
Problem
Solution
Discussion
Calculated properties
See Also
Create and Initialize Custom Objects
Problem
Solution
Discussion
See Also
Add Custom Methods and Properties to Types
Problem
Solution
Discussion
Getting started
Add a ScriptProperty
Add an AliasProperty
Add a ScriptMethod
Add other extension points
4. Looping and Flow Control
Introduction
Make Decisions with Comparison and Logical Operators
Problem
Solution
Discussion
See Also
Adjust Script Flow Using Conditional Statements
Problem
Solution
Discussion
Manage Large Conditional Statements with Switches
Problem
Solution
Discussion
See Also
Repeat Operations with Loops
Problem
Solution
Discussion
See Also
Add a Pause or Delay
Problem
Solution
Discussion
See Also
5. Strings and Unstructured Text
Introduction
Create a String
Problem
Solution
Discussion
See Also
Create a Multiline or Formatted String
Problem
Solution
Discussion
See Also
Place Special Characters in a String
Problem
Solution
Discussion
See Also
Insert Dynamic Information in a String
Problem
Solution
Discussion
See Also
Prevent a String from Including Dynamic Information
Problem
Solution
Discussion
See Also
Place Formatted Information in a String
Problem
Solution
Discussion
See Also
Search a String for Text or a Pattern
Problem
Solution
Discussion
See Also
Replace Text in a String
Problem
Solution
Discussion
See Also
Split a String on Text or a Pattern
Problem
Solution
Discussion
See Also
Combine Strings into a Larger String
Problem
Solution
Discussion
See Also
Convert a String to Upper/Lowercase
Problem
Solution
Discussion
See Also
Trim a String
Problem
Solution
Discussion
See Also
Format a Date for Output
Problem
Solution
Discussion
See Also
Program: Convert Text Streams to Objects
See Also
Generate Large Reports and Text Streams
Problem
Solution
Discussion
Creating large text reports
Generate Source Code and Other Repetitive Text
Problem
Solution
Discussion
6. Calculations and Math
Introduction
Perform Simple Arithmetic
Problem
Solution
Discussion
See Also
Perform Complex Arithmetic
Problem
Solution
Discussion
Working with any root
Working with degrees instead of radians
See Also
Measure Statistical Properties of a List
Problem
Solution
Discussion
Work with Numbers as Binary
Problem
Solution
Discussion
See Also
Simplify Math with Administrative Constants
Problem
Solution
Discussion
See Also
Convert Numbers Between Bases
Problem
Solution
Discussion
See Also
7. Lists, Arrays, and Hashtables
Introduction
Create an Array or List of Items
Problem
Solution
Discussion
See Also
Create a Jagged or Multidimensional Array
Problem
Solution
Discussion
See Also
Access Elements of an Array
Problem
Solution
Discussion
See Also
Visit Each Element of an Array
Problem
Solution
Discussion
See Also
Sort an Array or List of Items
Problem
Solution
Discussion
Determine Whether an Array Contains an Item
Problem
Solution
Discussion
See Also
Combine Two Arrays
Problem
Solution
Discussion
See Also
Find Items in an Array That Match a Value
Problem
Solution
Discussion
See Also
Compare Two Lists
Problem
Solution
Discussion
See Also
Remove Elements from an Array
Problem
Solution
Discussion
See Also
Find Items in an Array Greater or Less Than a Value
Problem
Solution
Discussion
See Also
Use the ArrayList Class for Advanced Array Tasks
Problem
Solution
Discussion
See Also
Create a Hashtable or Associative Array
Problem
Solution
Discussion
See Also
Sort a Hashtable by Key or Value
Problem
Solution
Discussion
See Also
8. Utility Tasks
Introduction
Get the System Date and Time
Problem
Solution
Discussion
See Also
Measure the Duration of a Command
Problem
Solution
Discussion
See Also
Read and Write from the Windows Clipboard
Problem
Solution
Discussion
See Also
Generate a Random Number or Object
Problem
Solution
Discussion
See Also
Program: Search the Windows Start Menu
See Also
Program: Show Colorized Script Content
Discussion
See Also
III. Common Tasks
9. Simple Files
Introduction
Get the Content of a File
Problem
Solution
Discussion
See Also
Search a File for Text or a Pattern
Problem
Solution
Discussion
See Also
Parse and Manage Text-Based Logfiles
Problem
Solution
Discussion
See Also
Parse and Manage Binary Files
Problem
Solution
Discussion
See Also
Create a Temporary File
Problem
Solution
Discussion
See Also
Search and Replace Text in a File
Problem
Solution
Discussion
Work with files encoded in Unicode or another (OEM) code page
Replace text using a pattern instead of plain text
Replace text that spans multiple lines
Replace text in large files
See Also
Program: Get the Encoding of a File
See Also
Program: View the Hexadecimal Representation of Content
See Also
10. Structured Files
Introduction
Access Information in an XML File
Problem
Solution
Discussion
See Also
Perform an XPath Query Against XML
Problem
Solution
Discussion
See Also
Convert Objects to XML
Problem
Solution
Discussion
See Also
Modify Data in an XML File
Problem
Solution
Discussion
Easily Import and Export Your Structured Data
Problem
Solution
Discussion
Store the Output of a Command in a CSV or Delimited File
Problem
Solution
Discussion
See Also
Import CSV and Delimited Data from a File
Problem
Solution
Discussion
See Also
Use Excel to Manage Command Output
Problem
Solution
Discussion
See Also
Parse and Interpret PowerShell Scripts
Problem
Solution
Discussion
See Also
11. Code Reuse
Introduction
Write a Script
Problem
Solution
Discussion
See Also
Write a Function
Problem
Solution
Discussion
See Also
Find a Verb Appropriate for a Command Name
Problem
Solution
Discussion
See Also
Write a Script Block
Problem
Solution
Discussion
See Also
Return Data from a Script, Function, or Script Block
Problem
Solution
Discussion
See Also
Package Common Commands in a Module
Problem
Solution
Discussion
See Also
Write Commands That Maintain State
Problem
Solution
Discussion
See Also
Selectively Export Commands from a Module
Problem
Solution
Discussion
See Also
Diagnose and Interact with Internal Module State
Problem
Solution
Discussion
See Also
Handle Cleanup Tasks When a Module Is Removed
Problem
Solution
Discussion
See Also
Access Arguments of a Script, Function, or Script Block
Problem
Solution
Discussion
Supporting PowerShell’s common parameters
Using the $args array
See Also
Add Validation to Parameters
Problem
Solution
Discussion
Defining parameter behavior
Defining parameter validation
See Also
Accept Script Block Parameters with Local Variables
Problem
Solution
Discussion
See Also
Dynamically Compose Command Parameters
Problem
Solution
Discussion
See Also
Provide -WhatIf, -Confirm, and Other Cmdlet Features
Problem
Solution
Discussion
See Also
Add Help to Scripts or Functions
Problem
Solution
Discussion
See Also
Add Custom Tags to a Function or Script Block
Problem
Solution
Discussion
See Also
Access Pipeline Input
Problem
Solution
Discussion
See Also
Write Pipeline-Oriented Scripts with Cmdlet Keywords
Problem
Solution
Discussion
See Also
Write a Pipeline-Oriented Function
Problem
Solution
Discussion
See Also
Organize Scripts for Improved Readability
Problem
Solution
Discussion
See Also
Invoke Dynamically Named Commands
Problem
Solution
Discussion
See Also
Program: Enhance or Extend an Existing Cmdlet
See Also
12. Internet-Enabled Scripts
Introduction
Download a File from the Internet
Problem
Solution
Discussion
See Also
Download a Web Page from the Internet
Problem
Solution
Discussion
See Also
Program: Get-PageUrls
See Also
Connect to a Web Service
Problem
Solution
Discussion
See Also
Program: Connect-WebService
See Also
Export Command Output as a Web Page
Problem
Solution
Discussion
Send an Email
Problem
Solution
Discussion
See Also
Program: Send-MailMessage
See Also
Program: Interact with Internet Protocols
See Also
13. User Interaction
Introduction
Read a Line of User Input
Problem
Solution
Discussion
See Also
Read a Key of User Input
Problem
Solution
Discussion
Program: Display a Menu to the User
See Also
Display Messages and Output to the User
Problem
Solution
Discussion
See Also
Provide Progress Updates on Long-Running Tasks
Problem
Solution
Discussion
Write Culture-Aware Scripts
Problem
Solution
Discussion
Date, time, and number formats
Complexity of user input and file content
Capitalization rules
Sorting rules
Other guidelines
See Also
Support Other Languages in Script Output
Problem
Solution
Discussion
See Also
Program: Invoke a Script Block with Alternate Culture Settings
See Also
Access Features of the Host’s User Interface
Problem
Solution
Discussion
Program: Add a Graphical User Interface to Your Script
See Also
Interact with UI Frameworks and STA Objects
Problem
Solution
Discussion
See Also
14. Debugging
Introduction
Prevent Common Scripting Errors
Problem
Solution
Discussion
See Also
Trace Script Execution
Problem
Solution
Discussion
See Also
Set a Script Breakpoint
Problem
Solution
Discussion
See Also
Debug a Script When It Encounters an Error
Problem
Solution
Discussion
See Also
Create a Conditional Breakpoint
Problem
Solution
Discussion
See Also
Investigate System State While Debugging
Problem
Solution
Discussion
See Also
Program: Watch an Expression for Changes
See Also
Program: Get Script Code Coverage
See Also
15. Tracing and Error Management
Introduction
Determine the Status of the Last Command
Problem
Solution
Discussion
View the Errors Generated by a Command
Problem
Solution
Discussion
See Also
Manage the Error Output of Commands
Problem
Solution
Discussion
See Also
Program: Resolve an Error
See Also
Configure Debug, Verbose, and Progress Output
Problem
Solution
Discussion
See Also
Handle Warnings, Errors, and Terminating Errors
Problem
Solution
Discussion
See Also
Output Warnings, Errors, and Terminating Errors
Problem
Solution
Discussion
See Also
Program: Analyze a Script’s Performance Profile
See Also
16. Environmental Awareness
Introduction
View and Modify Environment Variables
Problem
Solution
Discussion
See Also
Access Information About Your Command’s Invocation
Problem
Solution
Discussion
Scripts
Functions
Script blocks
Program: Investigate the InvocationInfo Variable
See Also
Find Your Script’s Name
Problem
Solution
Discussion
See Also
Find Your Script’s Location
Problem
Solution
Discussion
See Also
Find the Location of Common System Paths
Problem
Solution
Discussion
See Also
Get the Current Location
Problem
Solution
Discussion
See Also
Safely Build File Paths Out of Their Components
Problem
Solution
Discussion
Interact with PowerShell’s Global Environment
Problem
Solution
Discussion
See Also
Determine PowerShell Version Information
Problem
Solution
Discussion
17. Extend the Reach of Windows PowerShell
Introduction
Automate Programs Using COM Scripting Interfaces
Problem
Solution
Discussion
See Also
Program: Query a SQL Data Source
See Also
Access Windows Performance Counters
Problem
Solution
Discussion
Access Windows API Functions
Problem
Solution
Discussion
See Also
Program: Invoke Simple Windows API Calls
See Also
Define or Extend a .NET Class
Problem
Solution
Discussion
See Also
Add Inline C# to Your PowerShell Script
Problem
Solution
Discussion
See Also
Access a .NET SDK Library
Problem
Solution
Discussion
See Also
Create Your Own PowerShell Cmdlet
Problem
Solution
Discussion
Step 1: Download the PowerShell SDK
Step 2: Create a file to hold the cmdlet source code
Step 3: Compile the DLL
Step 4: Load the module
Step 6: Use the module
See Also
Add PowerShell Scripting to Your Own Program
Problem
Solution
Discussion
Step 1: Download the PowerShell SDK
Step 2: Create a file to hold the hosting source code
Step 3: Compile and run the example
See Also
18. Security and Script Signing
Introduction
Enable Scripting Through an Execution Policy
Problem
Solution
Discussion
Execution policies are not user restrictions
See Also
Disable Warnings for UNC Paths
Problem
Solution
Discussion
See Also
Sign a PowerShell Script, Module, or Formatting File
Problem
Solution
Discussion
See Also
Program: Create a Self-Signed Certificate
Discussion
See Also
Manage PowerShell Security in an Enterprise
Problem
Solution
Discussion
Apply PowerShell’s Group Policy templates
Deploy Microsoft Certificate Services
See Also
Block Scripts by Publisher, Path, or Hash
Problem
Solution
Discussion
See Also
Verify the Digital Signature of a PowerShell Script
Problem
Solution
Discussion
Securely Handle Sensitive Information
Problem
Solution
Discussion
See Also
Securely Request Usernames and Passwords
Problem
Solution
Discussion
See Also
Program: Start a Process as Another User
See Also
Program: Run a Temporarily Elevated Command
See Also
Securely Store Credentials on Disk
Problem
Solution
Save the credential’s password to disk
Recreate the credential from the password stored on disk
Discussion
See Also
Access User and Machine Certificates
Problem
Solution
Discussion
See Also
Program: Search the Certificate Store
See Also
Add and Remove Certificates
Problem
Solution
Discussion
See Also
Manage Security Descriptors in SDDL Form
Problem
Solution
Discussion
See Also
19. Integrated Scripting Environment
Introduction
Debug a Script
Problem
Solution
Discussion
See Also
Customize Text and User Interface Colors
Problem
Solution
Discussion
See Also
Connect to a Remote Computer
Problem
Solution
Discussion
See Also
Extend ISE Functionality Through Its Object Model
Problem
Solution
Discussion
See Also
Add an Item to the Tools Menu
Problem
Solution
Discussion
See Also
IV. Administrator Tasks
20. Files and Directories
Introduction
Determine the Current Location
Problem
Solution
Discussion
Get the Files in a Directory
Problem
Solution
Discussion
See Also
Find All Files Modified Before a Certain Date
Problem
Solution
Discussion
See Also
Clear the Content of a File
Problem
Solution
Discussion
See Also
Manage and Change the Attributes of a File
Problem
Solution
Discussion
See Also
Find Files That Match a Pattern
Problem
Solution
Discussion
See Also
Manage Files That Include Special Characters
Problem
Solution
Discussion
Program: Get Disk Usage Information
See Also
Monitor a File for Changes
Problem
Solution
Discussion
Get the Version of a DLL or Executable
Problem
Solution
Discussion
See Also
Program: Get the MD5 or SHA1 Hash of a File
See Also
Create a Directory
Problem
Solution
Discussion
Remove a File or Directory
Problem
Solution
Discussion
See Also
Rename a File or Directory
Problem
Solution
Discussion
See Also
Move a File or Directory
Problem
Solution
Discussion
See Also
Program: Move or Remove a Locked File
See Also
Get the ACL of a File or Directory
Problem
Solution
Discussion
See Also
Set the ACL of a File or Directory
Problem
Solution
Discussion
See Also
Program: Add Extended File Properties to Files
See Also
Program: Create a Filesystem Hard Link
See Also
Program: Create a ZIP Archive
See Also
21. The Windows Registry
Introduction
Navigate the Registry
Problem
Solution
Discussion
See Also
View a Registry Key
Problem
Solution
Discussion
Modify or Remove a Registry Key Value
Problem
Solution
Discussion
Create a Registry Key Value
Problem
Solution
Discussion
Remove a Registry Key
Problem
Solution
Discussion
See Also
Safely Combine Related Registry Modifications
Problem
Solution
Discussion
See Also
Add a Site to an Internet Explorer Security Zone
Problem
Solution
Discussion
See Also
Modify Internet Explorer Settings
Problem
Solution
Discussion
See Also
Program: Search the Windows Registry
See Also
Get the ACL of a Registry Key
Problem
Solution
Discussion
See Also
Set the ACL of a Registry Key
Problem
Solution
Discussion
See Also
Work with the Registry of a Remote Computer
Problem
Solution
Discussion
See Also
Program: Get Registry Items from Remote Machines
See Also
Program: Get Properties of Remote Registry Keys
See Also
Program: Set Properties of Remote Registry Keys
See Also
Discover Registry Settings for Programs
Problem
Solution
Discussion
Launch and configure Process Monitor
Prepare to manually set the configuration option
Tell Process Monitor to begin capturing information
Manually set the configuration option
Tell Process Monitor to stop capturing information
Review the capture logs for registry modification
Automate these registry writes
See Also
22. Comparing Data
Introduction
Compare the Output of Two Commands
Problem
Solution
Discussion
Determine the Differences Between Two Files
Problem
Solution
Discussion
Verify Integrity of File Sets
Problem
Solution
Discussion
See Also
23. Event Logs
Introduction
List All Event Logs
Problem
Solution
Discussion
See Also
Get the Newest Entries from an Event Log
Problem
Solution
Discussion
See Also
Find Event Log Entries with Specific Text
Problem
Solution
Discussion
See Also
Retrieve and Filter Event Log Entries
Problem
Solution
Discussion
Efficiently processing simple queries
Automating GUI-generated searches
Performing complex event analysis and correlation
See Also
Find Event Log Entries by Their Frequency
Problem
Solution
Discussion
See Also
Back Up an Event Log
Problem
Solution
Discussion
Create or Remove an Event Log
Problem
Solution
Discussion
See Also
Write to an Event Log
Problem
Solution
Discussion
See Also
Run a PowerShell Script for Windows Event Log Entries
Problem
Solution
Discussion
See Also
Clear or Maintain an Event Log
Problem
Solution
Discussion
See Also
Access Event Logs of a Remote Machine
Problem
Solution
Discussion
See Also
24. Processes
Introduction
List Currently Running Processes
Problem
Solution
Discussion
See Also
Launch the Application Associated with a Document
Problem
Solution
Discussion
See Also
Launch a Process
Problem
Solution
Discussion
See Also
Stop a Process
Problem
Solution
Discussion
Debug a Process
Problem
Solution
Discussion
See Also
25. System Services
Introduction
List All Running Services
Problem
Solution
Discussion
See Also
Manage a Running Service
Problem
Solution
Discussion
See Also
Configure a Service
Problem
Solution
Discussion
See Also
26. Active Directory
Introduction
Test Active Directory Scripts on a Local Installation
Problem
Solution
Discussion
Verify prerequisites
Install ADAM
Create a test instance
See Also
Create an Organizational Unit
Problem
Solution
Discussion
See Also
Get the Properties of an Organizational Unit
Problem
Solution
Discussion
Modify Properties of an Organizational Unit
Problem
Solution
Discussion
Delete an Organizational Unit
Problem
Solution
Discussion
Get the Children of an Active Directory Container
Problem
Solution
Discussion
See Also
Create a User Account
Problem
Solution
Discussion
See Also
Program: Import Users in Bulk to Active Directory
See Also
Search for a User Account
Problem
Solution
Discussion
Get and List the Properties of a User Account
Problem
Solution
Discussion
Modify Properties of a User Account
Problem
Solution
Discussion
Change a User Password
Problem
Solution
Discussion
See Also
Create a Security or Distribution Group
Problem
Solution
Discussion
See Also
Search for a Security or Distribution Group
Problem
Solution
Discussion
Get the Properties of a Group
Problem
Solution
Discussion
Find the Owner of a Group
Problem
Solution
Discussion
Modify Properties of a Security or Distribution Group
Problem
Solution
Discussion
Add a User to a Security or Distribution Group
Problem
Solution
Discussion
See Also
Remove a User from a Security or Distribution Group
Problem
Solution
Discussion
See Also
List a User’s Group Membership
Problem
Solution
Discussion
See Also
List the Members of a Group
Problem
Solution
Discussion
See Also
List the Users in an Organizational Unit
Problem
Solution
Discussion
See Also
Search for a Computer Account
Problem
Solution
Discussion
Get and List the Properties of a Computer Account
Problem
Solution
Discussion
27. Enterprise Computer Management
Introduction
Join a Computer to a Domain or Workgroup
Problem
Solution
Discussion
See Also
Remove a Computer from a Domain
Problem
Solution
Discussion
See Also
Program: List Logon or Logoff Scripts for a User
See Also
Program: List Startup or Shutdown Scripts for a Machine
See Also
Deploy PowerShell-Based Logon Scripts
Problem
Solution
Discussion
See Also
Enable or Disable the Windows Firewall
Problem
Solution
Discussion
See Also
Open or Close Ports in the Windows Firewall
Problem
Solution
Discussion
See Also
Program: List All Installed Software
See Also
Uninstall an Application
Problem
Solution
Discussion
See Also
Manage Computer Restore Points
Problem
Solution
Discussion
Reboot or Shut Down a Computer
Problem
Solution
Discussion
See Also
Determine Whether a Hotfix Is Installed
Problem
Solution
Discussion
Manage Scheduled Tasks on a Computer
Problem
Solution
Discussion
See Also
Retrieve Printer Information
Problem
Solution
Discussion
See Also
Retrieve Printer Queue Statistics
Problem
Solution
Discussion
See Also
Manage Printers and Print Queues
Problem
Solution
Discussion
See Also
Program: Summarize System Information
See Also
Renew a DHCP Lease
Problem
Solution
Discussion
Use the Win32_NetworkAdapterConfiguration WMI class
Run ipconfig on the remote computer
See Also
Assign a Static IP Address
Problem
Solution
Discussion
See Also
List All IP Addresses for a Computer
Problem
Solution
Discussion
Use the Win32_NetworkAdapterConfiguration WMI class
Run ipconfig on the remote computer
See Also
List Network Adapter Properties
Problem
Solution
Discussion
See Also
28. Windows Management Instrumentation
Introduction
Access Windows Management Instrumentation Data
Problem
Solution
Discussion
See Also
Modify the Properties of a WMI Instance
Problem
Solution
Discussion
See Also
Invoke a Method on a WMI Class
Problem
Solution
Discussion
See Also
Program: Determine Properties Available to WMI Filters
See Also
Program: Search for WMI Classes
See Also
Use .NET to Perform Advanced WMI Tasks
Problem
Solution
Advanced instance features
Advanced class features
Advanced query feature
Discussion
See Also
Improve the Performance of Large-Scale WMI Operations
Problem
Solution
Discussion
See Also
Convert a VBScript WMI Script to PowerShell
Problem
Solution
Discussion
Retrieving data
Calling methods on an instance
Calling methods on a class
See Also
29. Remoting
Introduction
Find Commands That Support Their Own Remoting
Problem
Solution
Discussion
See Also
Program: Invoke a PowerShell Expression on a Remote Machine
See Also
Test Connectivity Between Two Computers
Problem
Solution
Discussion
See Also
Limit Networking Scripts to Hosts That Respond
Problem
Solution
Discussion
See Also
Enable PowerShell Remoting on a Computer
Problem
Solution
Discussion
Enable remoting on a single local machine
Enable remoting on a remote machine
Enable remoting in an enterprise
See Also
Enable Remote Desktop on a Computer
Problem
Solution
Discussion
See Also
Program: Remotely Enable PowerShell Remoting
See Also
Configure User Permissions for Remoting
Problem
Solution
Discussion
See Also
Enable Remoting to Workgroup Computers
Problem
Solution
Discussion
Interactively Manage a Remote Computer
Problem
Solution
Discussion
See Also
Invoke a Command on a Remote Computer
Problem
Solution
Discussion
See Also
Implicitly Invoke Commands from a Remote Computer
Problem
Solution
Discussion
See Also
Create Sessions with Full Network Access
Problem
Solution
Discussion
See Also
Pass Variables to Remote Sessions
Problem
Solution
Discussion
See Also
Configure Advanced Remoting Options
Problem
Solution
Discussion
See Also
Invoke a Command on Many Computers
Problem
Solution
Discussion
See Also
Run a Local Script on a Remote Computer
Problem
Solution
Discussion
See Also
Program: Transfer a File to a Remote Computer
See Also
Determine Whether a Script Is Running on a Remote Computer
Problem
Solution
Discussion
See Also
Program: Create a Task-Specific Remoting Endpoint
See Also
30. Transactions
Introduction
Safely Experiment with Transactions
Problem
Solution
Discussion
See Also
Change Error Recovery Behavior in Transactions
Problem
Solution
Discussion
See Also
31. Event Handling
Introduction
Respond to Automatically Generated Events
Problem
Solution
Discussion
See Also
Create and Respond to Custom Events
Problem
Solution
Discussion
See Also
Create a Temporary Event Subscription
Problem
Solution
Discussion
See Also
Forward Events from a Remote Computer
Problem
Solution
Discussion
See Also
Investigate Internal Event Action State
Problem
Solution
Discussion
See Also
Use a Script Block as a .NET Delegate or Event Handler
Problem
Solution
Discussion
See Also
V. References
A. PowerShell Language and Environment
Commands and Expressions
Comments
Variables
Booleans
Strings
Literal and Expanding Strings
Here Strings
Escape Sequences
Numbers
Simple Assignment
Administrative Numeric Constants
Hexadecimal and Other Number Bases
Arrays and Lists
Array Definitions
Array Access
Array Slicing
Hashtables (Associative Arrays)
Hashtable Definitions
Hashtable Access
XML
Simple Operators
Arithmetic Operators
Logical Operators
Binary Operators
Other Operators
Comparison Operators
Conditional Statements
if, elseif, and else Statements
switch Statements
Looping Statements
for Statement
foreach Statement
while Statement
do … while Statement/do … until Statement
Flow Control Statements
break
continue
Working with the .NET Framework
Static Methods
Instance Methods
Static Properties
Instance Properties
Learning About Types
The Get-Member cmdlet
.NET Framework documentation
Type Shortcuts
Creating Instances of Types
Interacting with COM Objects
Extending Types
The Add-Member cmdlet
Custom type extension files
Writing Scripts, Reusing Functionality
Writing Commands
Writing scripts
Writing functions
Writing script blocks
Running Commands
Invoking
Dot-sourcing
Parameter splatting
Providing Input to Commands
Argument array
Formal parameters
Command behavior customizations
Parameter attribute customizations
Parameter validation attributes
Pipeline input
Cmdlet keywords in commands
$MyInvocation automatic variable
Retrieving Output from Commands
Pipeline output
Return statement
Exit statement
Help Documentation
Managing Errors
Nonterminating Errors
Terminating Errors
Formatting Output
Custom Formatting Files
Capturing Output
Common Customization Points
Console Settings
Adjust your window size
Make text selection easier
Use hotkeys to operate the shell more efficiently
Profiles
Prompts
Tab Completion
B. Regular Expression Reference
C. XPath Quick Reference
D. .NET String Formatting
String Formatting Syntax
Standard Numeric Format Strings
Custom Numeric Format Strings
E. .NET DateTime Formatting
Custom DateTime Format Strings
F. Selected .NET Classes and Their Uses
G. WMI Reference
H. Selected COM Objects and Their Uses
I. Selected Events and Their Uses
J. Standard PowerShell Verbs
Index
About the Author
Colophon
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
31. Event Handling
Next
Next Chapter
A. PowerShell Language and Environment
Part V. References
Appendix A
Appendix B
Appendix C
Appendix D
Appendix E
Appendix F
Appendix G
Appendix H
Appendix I
Appendix J
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset