You are previewing Sams Teach Yourself Windows PowerShell in 24 Hours.
O'Reilly logo
Sams Teach Yourself Windows PowerShell in 24 Hours

Book Description

In just 24 lessons of one hour or less, Sams Teach Yourself Windows PowerShell in 24 Hours helps you streamline all facets of Windows administration, supercharging your effectiveness as an IT professional or power user. This book’s straightforward, step-by-step approach shows you how to build and run scripts, extend Windows PowerShell reach, manage computers remotely, and automate a wide variety of tasks on any modern Windows server or client. Every lesson builds on what you’ve already learned, giving you a rock-solid foundation for real-world success!

Step-by-step instructions carefully walk you through the most common PowerShell scripting tasks.

Practical, hands-on examples show you how to apply what you learn.

Quizzes and exercises help you test your knowledge and stretch your skills.

Notes, tips, and cautions point out shortcuts, pitfalls, and solutions.

Learn how to...

  • Install, configure, and explore Windows PowerShell (including updates for PowerShell 5)

  • Leverage .NET’s remarkable power and scope with easy-to-use cmdlets

  • Build new scripts with the console, ISE visual tools, and other popular hosts

  • Apply best practices for writing more reliable, flexible, team-friendly scripts

  • Work effectively with the pipeline, objects, and data

  • Extend Windows PowerShell reach via providers, drives, and output

  • Run external tools like ping, ipconfig, and tracert from within PowerShell

  • Remotely manage computers with basic and advanced remoting (WinRM), WMI, and Regex

  • Configure Windows devices across the web with PSWA

  • Sort, filter, measure, format, export, and convert script output

  • Run Windows PowerShell flexibly, using background and scheduled jobs

  • Customize your environment with profile scripts, alternate credentials, thirdparty tools, and packages

  • Strengthen your control over Windows systems and services with Desired State Configuration

  • Administer key tasks on SQL Server, SharePoint, and other Windows servers

  • Master PowerShell skills needed to earn many Microsoft certifications

  • Table of Contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Contents at a Glance
    5. Table of Contents
    6. About the Author
    7. Dedication
    8. Acknowledgments
    9. We Want to Hear from You!
    10. Reader Services
    11. Introduction
      1. Who Should Read This Book
      2. How This Book Is Organized
      3. Conventions Used in This Book
        1. Try It Yourself
        2. About the Bitly Hyperlinks
        3. About the Code Images
      4. System Requirements
      5. Design Elements Used in This Book
    12. Part I: Introducing Windows PowerShell
      1. Hour 1. Getting to Know Windows PowerShell
        1. Why You Should Learn Windows PowerShell
          1. The Technology Is Not Going Away
          2. Some Tasks Can Be Accomplished Only with Windows PowerShell
          3. Windows PowerShell Is One Interface to Rule Them All
          4. You Won’t Pass Your Certification Exams Without Windows PowerShell Knowledge
          5. You Can “Future-Proof” Your IT Career by Mastering Windows PowerShell
        2. Brief History of Windows PowerShell
          1. Monad Manifesto
          2. Defining PowerShell
        3. Understanding the Windows PowerShell Components
          1. Windows PowerShell Console
          2. PowerShell Integrated Scripting Environment
          3. Other First- and Third-Party Windows PowerShell Hosts
        4. Investigating the Power and Simplicity of Windows PowerShell
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
      2. Hour 2. Installing and Configuring Windows PowerShell
        1. Determining Your Windows PowerShell Environment
          1. Determining Your .NET Framework Version
          2. Determining Your Windows Version
        2. Installing the Latest Version of Windows PowerShell
          1. WMF Components
          2. Installing the WMF
        3. Customizing the Windows PowerShell Console
        4. Customizing the Windows PowerShell ISE
          1. Verifying That the ISE Is Installed
          2. Mandatory ISE Tweaks
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
      3. Hour 3. Mastering the Windows PowerShell Help System
        1. Anatomy of a Windows PowerShell Cmdlet
          1. Noun Behavior in Windows PowerShell
        2. Updating the Windows PowerShell Help Library
          1. Understanding Updateable Help
          2. Viewing Help Content
          3. Updating Help on Offline Systems
        3. Understanding Windows PowerShell Help Syntax
          1. Defining Parameter Sets
          2. More Information About Parameters
        4. Accessing Additional Command Help
          1. The “About” File Library
          2. The –ShowWindow Parameter
          3. The Show-Command Cmdlet
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
      4. Hour 4. Finding and Discovering Windows PowerShell Commands
        1. How Windows PowerShell Commands Are Packaged
          1. Understanding Snap-Ins
          2. Understanding Modules
          3. Working with Windows PowerShell Modules
        2. Installing RSAT Tools on Windows 8.1
          1. What Is the RSAT?
        3. Locating Windows PowerShell Commands
          1. Verbs and Nouns, Revisited
          2. Getting Familiar with Get-Command
          3. Differentiating Get-Command and Get-Help
        4. Running External Commands
          1. External Command in Environment Path
          2. Invoke-Item
          3. The Call Operator
          4. The Stop Parsing Symbol
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
    13. Part II: Understanding Objects and the Pipeline
      1. Hour 5. Thinking in Terms of Objects
        1. The Problem with UNIX/Linux
        2. What Is an Object?
          1. Referencing Individual Objects
        3. Discovering Object Members
          1. Data Type
          2. Member Type
          3. Getting to Know Get-Member
        4. Putting Objects into Action
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
      2. Hour 6. Mastering the Windows PowerShell Pipeline
        1. Understanding How the Pipeline Works from a High Level
          1. Brief Case Study
        2. Understanding in Depth How the Pipeline Works
          1. First, Data Types
          2. Second, Parameters
        3. Passing Data Through the Pipeline
          1. Parameter Passing by Value
          2. Parameter Passing by Property Name
        4. “Forcing” Objects Through the Pipeline
          1. Case Study
          2. Introducing Hash Tables
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
      3. Hour 7. Sorting, Filtering, and Measuring Windows PowerShell Output
        1. Sorting Output
          1. Discovering Property Names
          2. Sorting on Multiple Criteria
          3. Adding Grouping to the Mix
        2. Filtering Output
          1. Using Select-Object
          2. Using Where-Object
          3. Comparison Operators in PowerShell
        3. Measuring Objects
          1. Delving Deeper into Measure-Object
          2. What Measure-Object Is and What It Isn’t
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
    14. Part III: Extending the Reach of Windows PowerShell
      1. Hour 8. Managing Windows PowerShell Providers
        1. What Are Providers?
          1. Functions Provided by a Provider
        2. Introduction to Default PSDrives
          1. A Familiar Navigation System
          2. What’s an Item?
        3. Using the FileSystem Provider
          1. Working with Get-ChildItem
        4. Using the Alias Provider
          1. Using the Alias PSDrive
        5. Using the Registry Provider
          1. Retrieving Registry Values
          2. Editing Registry Values
        6. Using Extended Providers
          1. Active Directory Provider
          2. SQL Server Provider
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
      2. Hour 9. Formatting, Exporting, and Converting Windows PowerShell Output
        1. How the PowerShell Formatting Subsystem Works
          1. Digging Deeper
          2. Out-GridView
        2. Formatting PowerShell Output
          1. Format-Table
          2. Format-List
          3. Format-Wide
        3. Exporting PowerShell Output
          1. Out-File
          2. Out-Printer
          3. Export-CSV
          4. Export-Clixml
        4. Converting PowerShell Output
          1. ConvertTo Options
          2. Your Final Exam
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
    15. Part IV: Managing Computers Remotely with Windows PowerShell
      1. Hour 10. Implementing One-to-One Windows PowerShell Remoting
        1. Understanding Classic Windows PowerShell Remote Access
          1. So, Should I Avoid the –ComputerName Parameter?
        2. Introducing “True” PowerShell Remoting
          1. WS-Man and WinRM
        3. Enabling Windows PowerShell Remoting
          1. Method 1: Enabling Remoting with Windows PowerShell
          2. Method 2: Enabling Remoting with Group Policy
          3. Method 3: Enabling Remoting in a Workgroup
        4. Creating a Windows PowerShell Remote Session
          1. Tweaking PowerShell Session Parameters
          2. Taking Control of Remote Sessions
          3. Using Variables and Alternate Credentials
        5. Sending Scripts over the Network
          1. Using Invoke-Command with Windows PowerShell Scripts
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
      2. Hour 11. Implementing One-to-Many Windows PowerShell Remoting
        1. One-to-Many Remote Access in the Classic Scenario
          1. Weaknesses with the Classic One-to-Many Model
        2. One-to-Many Remoting with Persistent Sessions
          1. Working with Disconnected Sessions
        3. Managing Session Configurations
          1. Creating a Constrained Endpoint
        4. One-to-Many Remoting with the Windows PowerShell ISE
          1. Creating a Remote Session Tab
        5. Passing Input to Remote Commands
          1. A Bit on Implicit Remoting
          2. Importing a Module from a Remote Computer
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
      3. Hour 12. Deploying Windows PowerShell Web Access
        1. Introducing Windows PowerShell Web Access
        2. Setting Up the Windows PSWA Gateway
          1. Installing the PSWA Feature
          2. Configuring the Gateway
          3. Defining Authorization Rules
        3. Testing the Windows PSWA User Experience
          1. Running Remote Windows PowerShell in a Web Browser
          2. Disconnecting and Reconnecting Sessions
        4. Managing the Gateway
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
    16. Part V: Putting Windows Powershell to Work
      1. Hour 13. Multitasking Windows PowerShell
        1. Investigating the PowerShell Job Architecture
          1. Starting a Background Job
          2. Checking Job Status
          3. Understanding Job Status Output
          4. Retrieving Job Data
        2. Controlling Job Behavior
          1. Stopping a Job
          2. Resuming a Stopped Job
          3. Deleting Jobs from the Queue
        3. Understanding Parent and Child Jobs
          1. Teasing Apart Parent and Child Jobs
        4. Introducing the –AsJob Parameter
          1. Sending Remote Jobs
        5. Scheduling Jobs
          1. Creating an On-Demand Scheduled Job
          2. Adding Triggers to Scheduled Jobs
          3. Pulling Data from PowerShell Scheduled Jobs
        6. Reviewing What We’ve Learned
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
      2. Hour 14. Harnessing Windows PowerShell Workflow
        1. Understanding How PowerShell Workflow Operates
          1. Attributes of a Windows PowerShell Workflow
          2. Taking Care of Preliminaries
        2. Writing Your First Windows PowerShell Workflow
          1. The Nonworkflow Method
          2. Defining the Workflow
        3. Running a Workflow as a Job
          1. Refactoring the Script for Multiple Targets
        4. Understanding Workflow Activities
          1. Checkpointing a Workflow
          2. Suspending and Resuming a Workflow
          3. Adding a Sequence to a Workflow
        5. Tying Everything Together
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
      3. Hour 15. Introducing WMI and CIM
        1. Defining WMI and CIM
          1. Where Does WMI Exist?
        2. Getting Comfortable with WMI
          1. A Quick Primer of WMI Terminology
          2. WMI Browser Tools
          3. Some Useful WMI Classes
        3. Using Windows PowerShell WMI Commands
          1. Using Get-WMIObject
          2. Dipping Our Toes into WQL
          3. Querying the WMI Repository Remotely
          4. Combining Background Jobs with Remote WMI Calls
          5. Calling WMI Methods
        4. Using Windows PowerShell CIM Commands
          1. What’s the Deal with CIM Cmdlets?
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
      4. Hour 16. Searching and Filtering with Regular Expressions
        1. Revisiting the Wildcard Operators
          1. Traditional Wildcard Search Syntax
        2. Understanding Regular Expressions
          1. Where to Use Regular Expressions in PowerShell
          2. Setting Up Our Test Environment
        3. Using the –Match Parameter
          1. Using RegEx Anchors and Ranges
          2. Using RegEx Qualifiers
          3. Using RegEx Character Classes
        4. Using Select-String
          1. A Practical Select-String Example
        5. Using the RegEx Type Accelerator
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
    17. Part VI: Enterprise-Class Windows PowerShell
      1. Hour 17. Managing Software with Windows PowerShell OneGet
        1. Understanding IT-Related Terminology
          1. Package
          2. Package Manager
          3. Repository
          4. OneGet
        2. Preparing Your Environment
          1. Retrieving Package Providers
        3. Browsing Package Repositories
          1. Using Find-Package
          2. Using Out-GridView
          3. Where’s the Documentation?
        4. Installing Software from the Command Line
          1. Where Was the Software Installed?
          2. Installing an Application from a Subdirectory
        5. Managing Providers and Packages
          1. Upgrading Installed Packages
          2. Removing Packages
        6. Hosting a Private OneGet Repository
          1. Using a File Share
          2. Using a Third-Party Tool
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
      2. Hour 18. Desired State Configuration Basics
        1. Historical Background of DSC
          1. Competitive Landscape
        2. Basic Tenets of DSC
        3. DSC Authoring Environment
          1. DSC Production Environment
        4. Configuring the DSC Environment
          1. Loading Up DSC Resources
          2. DSC Resource Waves
        5. Writing Your First Configuration Script
          1. Customizing the Local Configuration Manager
        6. A Word on DSC Push Configuration
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
    18. Part VII: Scripting with Windows PowerShell
      1. Hour 19. Introduction to Windows PowerShell Scripting
        1. Managing Execution Policy
          1. Script Execution Options
          2. Viewing and Setting the Execution Policy
          3. A Question of Scope
        2. Writing Our First Script: The User Profile
          1. Creating Our User Profile Script
          2. PowerShell Profile Gotchas
        3. Writing a PowerShell Function
          1. Introducing Snippets
          2. Functions and Quotes
        4. Adding Programming Logic
          1. Additional ISE Niceties
        5. Running Scripts
          1. Running Scripts from PowerShell
        6. Pointers to Master PowerShell Scripting
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
      2. Hour 20. Making PowerShell Code Portable with Modules
        1. Understanding Snap-Ins
          1. Defining Good Snap-Ins
          2. Adding a PSSnapin to Your Session
          3. Automating Snap-Ins
        2. Introducing PowerShell Modules
          1. Understanding the Module Types
          2. Loading and Unloading Modules
        3. Creating Your First PowerShell Script Module
          1. Creating the Actual Module
          2. Running Commands Inside a Module
          3. Use Approved Verbs
        4. Using Module Manifests
          1. How to Build a Manifest
          2. Troubleshooting Manifests
        5. Adding Comment-Based Help
        6. Finding Modules Easily
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
    19. Part VIII: Administering Microsoft Enterprise Servers with Windows PowerShell
      1. Hour 21. Managing Active Directory with Windows PowerShell
        1. Installing Active Directory
          1. Testing for Domain Membership
          2. Joining a Domain
          3. Installing the Active Directory Binaries
          4. Promoting the Domain Controller
          5. Installing a New Child Domain
        2. Creating Common Active Directory Objects
          1. Creating Organizational Units
          2. Creating Groups
          3. Creating User Accounts
          4. Managing User Accounts
        3. Undertaking Various AD Administrative Tasks
          1. Managing FSMO Roles
          2. Transferring FSMO Roles
          3. Handling Forest and Domain Functional Levels
          4. Administering Group Policy
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
      2. Hour 22. Managing SQL Server with Windows PowerShell
        1. Running PowerShell Using SQL Server Tools
          1. Installing the Management Tools
        2. Interacting with SQL Server Using PowerShell
        3. Automating Common SQL Server DBA Tasks
          1. Listing Databases within an Instance
          2. Creating a New Database
          3. Creating a New Table
          4. Inserting Data into a Table
          5. Running Select Queries Against Table Data
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
      3. Hour 23. Managing SharePoint Server with Windows PowerShell
        1. Understanding the Environment
          1. SharePoint Management Shell
          2. Probing the SharePoint Snap-in
          3. Creating a SharePoint Managed Account
        2. Deploying a Service Application
        3. Deploying a Web Application
        4. Deploying a Site Collection
        5. Setting Permissions on a Site Collection
          1. Dealing with Permissions in SharePoint
        6. Reporting on a SharePoint Farm
          1. Viewing Web Applications
          2. Viewing Site Collections
          3. Viewing Sites
          4. Viewing Lists and Libraries
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
      4. Hour 24. Managing Microsoft Azure with Windows PowerShell
        1. Defining Microsoft Azure
          1. Microsoft Azure Features
          2. Azure Management Portal
          3. Security Implications of the Microsoft Public Cloud
        2. Preparing Your Azure-PowerShell Environment
          1. Obtaining the Microsoft Azure PowerShell Module
          2. Testing the Module Installation
          3. Connecting to Your Azure Subscription
        3. Working with Azure Virtual Machines
          1. Creating a VM in the Cloud
          2. Interacting with Azure VMs
          3. Starting and Stopping Azure VMs
        4. Managing Office 365 and SharePoint Online with Azure
          1. Downloading and Installing the Prerequisite Software
          2. Adding SharePoint Online to the Mix
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
    20. Index
    21. Code Snippets