Windows PowerShell™ Scripting Guide

Book description

Get practical guidance for using Windows PowerShell to manage Windows Vista and Windows Server 2008. Written by Ed Wilson, a leading scripting expert and trainer at Microsoft, this reference offers a task-based approach to help you find the information you need for day-to-day tasks. With more than 200 scripts, it offers rich examples that administrators can customize for their own environment and needs. The scripts range in complexity from one-line commands, to full-blown scripts with managed output and command-line arguments examples that are applicable to all skill levels. Includes a companion CD with fully searchable eBook, sample scripts, and other resources for managing your Windows-based environment.

Key Book Benefits

Delivers more than 200 scripts administrators can customize and use to get up and running quickly

Provides multiple ways of accomplishing tasks: from one-line commands to full-blown scripts with managed output and command-line arguments

Features a task-oriented approach, and organized to help you quickly find the information you need for your day-to-day activities

Includes a companion CD with a fully searchable eBook, sample scripts, and other resources for on-the-job results

Table of contents

  1. Windows PowerShell™ Scripting Guide
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. A Note Regarding Supplemental Files
    3. Acknowledgments
    4. Introduction
      1. Is This Book for Me?
      2. About the Companion CD
      3. System Requirements
      4. Technical Support
    5. 1. The Shell in Windows PowerShell
      1. Installing Windows PowerShell
        1. Verifying Installation with VBScript
        2. Deploying Windows PowerShell
      2. Interacting with the Shell
      3. Introducing Cmdlets
      4. Configuring Windows PowerShell
        1. Creating a Windows PowerShell Profile
        2. Configuring Windows PowerShell Startup Options
      5. Security Issues with Windows PowerShell
        1. Controlling the Execution of Cmdlets
        2. Confirming Commands
        3. Suspending Confirmation of Cmdlets
      6. Supplying Options for Cmdlets
      7. Working with Get-Help
      8. Working with Aliases to Assign Shortcut Names to Cmdlets
      9. Additional Uses of Cmdlets
        1. Using the Get-ChildItem Cmdlet
        2. Formatting Output
          1. Format-List
          2. Format-Table
          3. Format-Wide
        3. Using the Get-Command Cmdlet
        4. Exploring with the Get-Member Cmdlet
      10. Summary
    6. 2. Scripting Windows PowerShell
      1. Why Use Scripting?
      2. Configuring the Scripting Policy
      3. Running Windows PowerShell Scripts
      4. Use of Variables
      5. Use of Constants
      6. Using Flow Control Statements
        1. Adding Parameters to ForEach-Object
        2. Using the Begin Parameter
        3. Using the Process Parameter
        4. Using the End Parameter
      7. Using the For Statement
      8. Using Decision-Making Statements
        1. Using If … Elseif … Else
        2. Using Switch
          1. Evaluating Command-Line Arguments
          2. Using Switch Wildcards
          3. Using Switch with Regular Expressions
      9. Working with Data Types
      10. Unleashing the Power of Regular Expressions
      11. Using Command-Line Arguments
      12. Summary
    7. 3. Managing Logs
      1. Identifying the Event Logs
      2. Reading the Event Logs
        1. Exporting to Text
        2. Export to XML
      3. Perusing General Log Files
        1. Examining Multiple Logs
        2. Retrieving a Single Event Log Entry
      4. Searching the Event Log
        1. Filtering on Properties
        2. Selecting the Source
        3. Selecting the Severity
        4. Selecting the Message
      5. Managing the Event Log
        1. Identifying the Sources
        2. Modifying the Event Log Settings
      6. Examining WMI Event Logs
        1. Making Changes to the WMI Logging Level
        2. Using the Windows Event Command-Line Utility
      7. Writing to Event Logs
        1. Creating a Source
        2. Putting Cmdlet Output into the Log
      8. Creating Your Own Event Logs
      9. Summary
    8. 4. Managing Services
      1. Documenting the Existing Services
        1. Working with Running Services
        2. Writing to a Text File
        3. Writing to a Database
          1. Writing Stopped Services
          2. Writing Service Configuration
      2. Setting the Service Configuration
        1. Accepting Command-Line Arguments
        2. Stopping Services
        3. Performing a Graceful Stop
        4. Starting Services
        5. Performing a Graceful Start
      3. Desired Configuration Maintenance
        1. Verifying Desired Services Are Stopped
        2. Reading a File to Check Service Status
        3. Verifying Desired Services Are Running
      4. Confirming the Configuration
      5. Producing an Exception Report
      6. Summary
    9. 5. Managing Shares
      1. Documenting Shares
        1. Documenting User Shares
        2. Writing Shares to Text
        3. Documenting Administrative Shares
        4. Writing Share Information to a Microsoft Access Database
      2. Auditing Shares
      3. Modifying Shares
        1. Using Parameters with the Script
        2. Translating the Return Code
      4. Creating New Shares
      5. Creating Multiple Shares
      6. Deleting Shares
      7. Deleting Only Unauthorized Shares
      8. Summary
    10. 6. Managing Printing
      1. Inventorying Printers
        1. Querying Multiple Computers
        2. Logging to a File
        3. Writing to a Microsoft Access Database
      2. Reporting on Printer Ports
      3. Identifying Printer Drivers
      4. Installing Printer Drivers
        1. Installing Printer Drivers Found on Your Computer
        2. Installing Printer Drivers Not Found on Your Computer
      5. Summary
    11. 7. Desktop Maintenance
      1. Maintaining Desktop Health
        1. Inventorying Drives
        2. Writing Disk Drive Information to Microsoft Access
        3. Working with Partitions
        4. Matching Disks and Partitions
        5. Working with Logical Disks
      2. Monitoring Disk Space Utilization
        1. Logging Disk Space to a Database
        2. Monitoring File Longevity
      3. Monitoring Performance
        1. Using Performance Counter Classes
        2. Identifying Sources of Page Faults
      4. Summary
    12. 8. Networking
      1. Working with Network Settings
        1. Reporting Networking Settings
        2. Working with Adapter Configuration
        3. Filtering Only Properties that Have a Value
      2. Configuring Network Adapter Settings
        1. Detecting Multiple Network Adapters
        2. Writing Network Adapter Information to a Microsoft Excel Spreadsheet
        3. Identifying Connected Network Adapters
        4. Setting Static IP Address
        5. Enabling DHCP
      3. Configuring the Windows Firewall
        1. Reporting Firewall Settings
        2. Configuring Firewall Settings
      4. Summary
    13. 9. Configuring Desktop Settings
      1. Working with Desktop Configuration Issues
      2. Setting Screen Savers
        1. Auditing Screen Savers
        2. Listing Only Properties with Values
        3. Reporting Secure Screen Savers
      3. Managing Desktop Power Settings
      4. Changing the Power Scheme
      5. Summary
    14. 10. Managing Post-Deployment Issues
      1. Setting the Time
        1. Setting the Time Remotely
        2. Logging Results to the Event Log
      2. Configuring the Time Source
        1. Using the Net Time Command
        2. Querying the Registry for the Time Source
      3. Enabling User Accounts
      4. Creating a Local User Account
        1. Creating a Local User
        2. Creating a Local User Group
      5. Configuring the Screen Saver
      6. Renaming the Computer
      7. Shutting Down or Rebooting a Remote Computer
      8. Summary
    15. 11. Managing User Data
      1. Working with Backups
      2. Configuring Offline Files
      3. Enabling the Use of Offline Files
      4. Working with System Restore
        1. Retrieving System Restore Settings
        2. Listing Available System Restore Points
      5. Summary
    16. 12. Troubleshooting Windows
      1. Troubleshooting Startup Issues
        1. Examining the Boot Configuration
        2. Examining Startup Services
      2. Displaying Service Dependencies
        1. Examining Startup Device Drivers
        2. Investigating Startup Processes
      3. Investigating Hardware Issues
      4. Troubleshooting Network Issues
      5. Summary
    17. 13. Managing Domain Users
      1. Creating Organizational Units
      2. Creating Domain Users
      3. Modifying User Attributes
        1. Modifying General User Information
        2. Modifying the Address Tab
        3. Modifying the Profile Tab
        4. Modifying the Telephone Tab
        5. Modifying the Organization Tab
        6. Modifying a Single User Attribute
      4. Creating Users from a .csv File
        1. Setting the Password
        2. Enabling the User Account
      5. Creating Domain Groups
      6. Adding a User to a Domain Group
      7. Adding Multiple Users with Multiple Attributes
      8. Summary
    18. 14. Configuring the Cluster Service
      1. Examining the Clustered Server
        1. Reporting Cluster Configuration
        2. Reporting Node Configuration
        3. Querying Multiple Cluster Classes
      2. Managing Nodes
        1. Adding and Evicting Nodes
        2. Removing the Cluster
      3. Summary
    19. 15. Managing Internet Information Services
      1. Enabling Internet Information Services Management
      2. Reporting IIS Configuration
        1. Reporting Site Information
        2. Reporting on Application Pools
        3. Reporting on Application Pool Default Values
        4. Reporting Site Limits
        5. Listing Virtual Directories
      3. Creating a New Web Site
      4. Creating a New Application Pool
      5. Starting and Stopping Web Sites
      6. Summary
    20. 16. Working with the Certificate Store
      1. Locating Certificates in the Certificate Store
        1. Listing Certificates
        2. Locating Expired Certificates
        3. Identifying Certificates about to Expire
      2. Managing Certificates
        1. Inspecting a Certificate
        2. Importing a Certificate
        3. Deleting a Certificate
      3. Summary
    21. 17. Managing the Terminal Services Service
      1. Configuring the Terminal Service Installation
        1. Documenting Terminal Service Configuration
        2. Disabling Logons
        3. Modifying Client Properties
      2. Managing Users
        1. Enabling Users to Access the Server
        2. Configuring Client Settings
      3. Summary
    22. 18. Configuring Network Services
      1. Reporting DNS Settings
        1. Configuring DNS Logging Settings
        2. Reporting Root Hints
        3. Querying "A" Records
      2. Configuring DNS Server Settings
      3. Reporting DNS Zones
      4. Creating DNS Zones
      5. Managing WINS and DHCP
      6. Summary
    23. 19. Working with Windows Server 2008 Server Core
      1. Initial Configuration
        1. Joining the Domain
        2. Setting the IP Address
        3. Configuring the DNS Settings
        4. Renaming the Server
      2. Managing Windows Server 2008 Server Core
        1. Monitoring the Server
        2. Querying Event Logs
      3. Summary
    24. A. Cmdlet Naming Conventions
    25. B. ActiveX Data Object Provider Names
    26. C. Frequently Asked Questions
    27. D. Scripting Guidelines
      1. General Script Construction
        1. Include Functions in the Script that Calls the Function
        2. Use Full Cmdlet Names and Full Parameter Names
          1. Understanding the Use of Aliases
          2. If You Must Use an Alias, Use Only Canonical Aliases in a Script
          3. Always Use the Description Property when Creating an Alias
          4. Use Get-Item to Convert Path Strings to Rich Types
      2. General Script Readability
      3. Formatting Your Code
        1. Working with Functions
        2. Creating Template Files
        3. Writing Functions
        4. Creating and Naming Variables and Constants
    28. E. General Troubleshooting Tips
    29. Index
    30. SPECIAL OFFER: Upgrade this ebook with O’Reilly

Product information

  • Title: Windows PowerShell™ Scripting Guide
  • Author(s):
  • Release date: January 2008
  • Publisher(s): Microsoft Press
  • ISBN: 9780735622791