O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Windows PowerShell Unleashed

Book Description

A new edition of this title is available, ISBN-10: 0672329883 ISBN-13: 9780672329883

PowerShell is one of the most exciting new products to come out of Microsoft in a long time. It is both a new scripting language and a command-line shell. People who have seen the demos have been extremely impressed by the power it brings to admins to automate and customize their regular tasks. PowerShell will be used as the basis for all Windows administrative scripting in the future, starting with Exchange 2007 and Vista. IT Pros have been hungering for whatever PowerShell information they can get their hands on.

This book first focuses on PowerShell basics, how it relates to existing Windows scripting practices, and how your existing knowledge can be translated into PowerShell knowledge. After gaining insight into PowerShell, you are presented with transferable PowerShell scripting examples. The goal of presenting these examples is to outline methods of using PowerShell to manage Windows Server, Active Directory, and Exchange Server 2007 that have not been explained or touched upon by other sources.


  • Understand PowerShell's basics and background

  • Script using PowerShell

  • Transfer existing Windows scripting skills to PowerShell

  • Analyze how PowerShell can be used to solve real-world problems

  • Manage the Windows File System, the Windows registry, Active Directory, and Exchange using PowerShell

  • Manage Systems using WMI and PowerShell

  • Customize PowerShell to meet your needs

  • Script using best practices.

  • Digitally sign your PowerShell scripts

  • Introduction

    Part I Introduction to PowerShell

    1 Introduction to Shells and PowerShell

    2 PowerShell Basics

    3 PowerShell: A More In-Depth Look

    4 Code Signing

    5 PowerShell Scripting Best Practices

    Part II Translating Your Existing Knowledge into PowerShell

    6 PowerShell and the File System

    7 PowerShell and the Registry

    8 PowerShell and WMI

    9 PowerShell and Active Directory

    Part III Using PowerShell to Meet Your Automation Needs

    10 Using PowerShell in the Real-World


    Table of Contents

    1. Copyright
      1. Dedication
    2. About the Author
    3. Acknowledgments
    4. We Want to Hear from You!
    5. Introduction
      1. Who Is This Book’s Intended Audience?
      2. How This Book Is Organized
      3. Conventions Used in This Book
        1. Black Code Boxes
        2. Gray Code Boxes
    6. I. Introduction to PowerShell
      1. 1. Introduction to Shells and PowerShell
        1. What Is a Shell?
          1. Basic Shell Use
          2. Basic Shell Scripts
        2. A Shell History
        3. Enter PowerShell
        4. Summary
      2. 2. PowerShell Basics
        1. Introduction
        2. Getting Started
        3. Accessing PowerShell
        4. Understanding the Command-Line Interface (CLI)
          1. Navigating the CLI
          2. PowerShell Command Types
            1. cmdlet
            2. Shell Function Commands
            3. Script Commands
            4. Native Commands
          3. Calling PowerShell from Other Shells
        5. Understanding cmdlets
          1. Common Parameters
        6. Useful cmdlets
          1. Get-Help
            1. cmdlet Help Topics
          2. Get-Command
        7. Expressions
        8. Understanding Variables
          1. Built-in Variables
        9. Understanding Aliases
          1. Discovering Alias cmdlets
          2. Creating Persistent Aliases
        10. Escape Sequences
        11. Understanding Scopes
          1. Global
          2. Local
          3. Script
          4. Private
        12. Your First Script
        13. Summary
      3. 3. PowerShell: A More In-Depth Look
        1. Introduction
        2. Object Based
          1. Understanding the Pipeline
          2. .NET Framework Tips
            1. New-Object cmdlet
            2. Square Brackets
            3. Static Classes and Methods
            4. Reflection
            5. Extended Type System (ETS)
        3. Understanding Providers
          1. Accessing Drives and Data
          2. Mounting a Drive
        4. Understanding Errors
        5. Error Handling
          1. Method One: cmdlet Preferences
          2. Method Two: Trapping Errors
            1. Trap Examples
            2. Trap Scopes
          3. Method Three: The Throw Keyword
        6. PowerShell Profiles
          1. The All Users Profile
          2. The All Users Host-Specific Profile
          3. The Current User’s Profile
          4. The Current User’s Host-Specific Profile
        7. Understanding Security
          1. Execution Policies
            1. Restricted
            2. AllSigned
            3. RemoteSigned
            4. Unrestricted
          2. Setting the Execution Policy
          3. Additional Security Measures
        8. The PowerShell Language
        9. Summary
      4. 4. Code Signing
        1. Introduction
        2. What Is Code Signing?
        3. Obtaining a Code-Signing Certificate
          1. Method One: Self-Signed Certificate
          2. Method Two: CA Signed Certificate
          3. The PVK Digital Certificate Files Importer
        4. Signing PowerShell Scripts
        5. Verifying Digital Signatures
        6. Signed Code Distribution
          1. Enterprise Code Distribution
          2. Public Code Distribution
        7. Summary
      5. 5. PowerShell Scripting Best Practices
        1. Introduction
        2. Script Development
          1. Treat Scripting Projects as Actual Projects
          2. Use a Development Life Cycle Model
          3. Design and Prototype Your Scripts by Using Pseudocode
          4. Gather Script Requirements Effectively
          5. Don’t Develop Scripts in a Production Environment
          6. Test, Test, Test
          7. Keep Your Scripts Professional
        3. Script Design
          1. Put Configuration Information at the Beginning of Script
          2. Use Comments
          3. Avoid Hard-Coding Configuration Information
          4. When Necessary, Use Variables
          5. Provide Instructions
          6. Perform Validity Checking on Required Parameters
          7. Make Scripts and Functions Reusable
          8. Use Descriptive Names Rather Than Aliases
          9. Provide Status Information for Script Users
          10. Use the WhatIf and Confirm Parameters
        4. Script Security
          1. Digitally Sign PowerShell Scripts and Configuration Files
          2. Never Set Execution Policies to Unrestricted
          3. Try to Run Scripts with the Minimum Required Rights
        5. Standards for Scripting
          1. This Book’s Scripting Standards
        6. Summary
    7. II. Translating Your Existing Knowledge into PowerShell
      1. 6. PowerShell and the File System
        1. Introduction
        2. File System Management in WSH and PowerShell
          1. Working with Drives
          2. Working with Folders
          3. Working with Files
        3. Working with Permissions
          1. Setting Permissions with SubInACL
            1. SubInACL Functions
          2. Setting Permissions in PowerShell
            1. PowerShell Functions
        4. From VBScript to PowerShell
          1. The ProvisionWebFolders.wsf Script
          2. The ProvisionWebFolders.ps1 Script
        5. Summary
      2. 7. PowerShell and the Registry
        1. Introduction
        2. Registry Management in WSH and PowerShell
        3. From VBScript to PowerShell
          1. The LibraryRegistry.vbs Script
          2. The LibraryRegistry.ps1 Script
            1. Using the Library
        4. Summary
      3. 8. PowerShell and WMI
        1. Introduction
        2. Comparing WMI Usage Between WSH and PowerShell
          1. Using WMI in WSH
            1. Step One
            2. Step Two
            3. Step Three
          2. Using WMI in PowerShell
          3. Type Accelerators
            1. [WMI] Type Accelerator
            2. [WMIClass] Type Accelerator
            3. [WMISearcher] Type Accelerator
        3. From VBScript to PowerShell
          1. The MonitorMSVS.wsf Script
          2. The MonitorMSVS.ps1 Script
        4. Summary
      4. 9. PowerShell and Active Directory
        1. Introduction
        2. Comparing ADSI Usage Between WSH and PowerShell
          1. Using ADSI in WSH
          2. Using ADSI with PowerShell
          3. Retrieving Object Information
          4. Creating an Object
        3. From VBScript to PowerShell
          1. The IsGroupMember.wsf Script
          2. The IsGroupMember.ps1 Script
        4. Summary
    8. III. Using PowerShell to Meet Your Automation Needs
      1. 10. Using PowerShell in the Real-World
        1. The PSShell.ps1 Script
          1. Component One: Shell Replacement
            1. Step One: Creating the PSShell Secure Kiosk GPO
            2. Step Two: Configuring the Windows Shell Replacement Settings
          2. Component Two: PSShell.exe
          3. Component Three: PSShell.ps1
          4. Putting It All Together
        2. The ChangeLocalAdminPassword.ps1 Script
        3. Summary
      2. 11. Using PowerShell to Manage Exchange
        1. Introduction
        2. The Exchange Management Shell (EMS)
          1. It’s Just a Snap-in
        3. The GetDatabaseSizeReport.ps1 Script
        4. The GetEvent1221Info.ps1 Script
        5. The ProvisionExchangeUsers.ps1 Script
        6. Summary