Learning PowerShell DSC - Second Edition

Book description

A learning guide to get you started with PowerShell DSC.

About This Book

  • Create flexible and maintainable deployments using DSC configuration scripts that stand the test of time.
  • Explore the core architecture, concepts, and practices in depth.
  • Learning PowerShell DSC is a step-by-step guide that shows you how to start using and taking advantage of PowerShell DSC along with configuring and deploying applications.

Who This Book Is For

If you are a system administrator, developer, or engineer and are responsible for configuration management and automation, then this book is for you. IT professionals who wish to learn PowerShell Desired State Configuration for the efficient management, configuration, and deployment of systems will also find this book useful.

What You Will Learn

  • Explore PowerShell Desired State Configuration and activities around it, including the need for configuration management and abstraction.
  • Create reusable DSC configurations and debug/ troubleshoot configuration files.
  • Learn about the PowerShell DSC architecture with the help of push-and-pull management and workflows.
  • Define DSC configuration scripts and data files and push DSC configuration files remotely and locally.
  • Validate DSC Pull Server install and register target nodes with a DSC Pull Server.
  • Learn about DSC Cross Platform and install PowerShell on Linux and macOS along with real-life DSC uses and different types of deployment.

In Detail

The main goal of this book is to teach you to configure, deploy, and manage your system using the new features of PowerShell v5/v6 DSC.

This book begins with the basics of PowerShell Desired State Configuration, covering its architecture and components. It familiarizes you with the set of Windows PowerShell language extensions and new Windows PowerShell commands that make up DSC. Then it helps you create DSC custom resources and work with DSC configurations with the help of practical examples. Finally, it describes how to deploy configuration data using PowerShell DSC. Throughout this book, we will be focusing on concepts such as building configurations with parameters, the local configuration manager, and testing and restoring configurations using PowerShell DSC.

By the end of the book, you will be able to deploy a real-world application end-to-end and will be familiar enough with the powerful Desired State Configuration platform to achieve continuous delivery and efficiently and easily manage and deploy data for systems.

Style and approach

The purpose of this book is to introduce readers to the powerful PowerShell Desired State Configuration platform to achieve continuous delivery, efficient management, and the easy deployment of data for systems.

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Introducing PowerShell DSC
    1. What is PowerShell DSC?
      1. What is PowerShell?
      2. On to PowerShell DSC
    2. Why do we need configuration management?
      1. What is DevOps?
    3. DSC quick wins
    4. DSC high-level overview
      1. The authoring phase
      2. The staging phase
      3. The execution phase
    5. Why all the abstraction?
    6. How does DSC help?
      1. The who
      2. The what
      3. The how
      4. Idempotence
      5. Isn't this Group Policy or SCCM?
    7. DSC features
      1. DSC requirements
      2. DSC versions
    8. PowerShell V4 DSC
      1. V4 DSC language extensions
      2. V4 DSC base resources
      3. V4 DSC cmdlets
      4. V4 DSC pull server
    9. PowerShell V5 DSC
      1. V5 DSC language extensions
      2. V5 DSC base resources
      3. V5 DSC cmdlets
      4. V5 improvements
        1. The PowerShell ISE
        2. Partial configurations and dependencies
        3. Class-based DSC resources
        4. DSC built-in support for help
        5. DSC run as credential support
        6. DSC resource side-by-side installation
        7. DSC resource script debugging
        8. Separation of node and configuration IDs
        9. DSC LCM MetaConfig updates
        10. DSC LCM rich state information
        11. DSC LCM RefreshMode values
        12. DSC status from a central location
    10. PowerShell V6 DSC
    11. Summary
  3. DSC Architecture
    1. Overview
    2. Push and pull modes
      1. The push management model
      2. The pull management model
    3. The general workflow
      1. Authoring
        1. Syntax
        2. Compilation
      2. Staging
      3. Execution
        1. Push executions
        2. Pull executions
    4. The example workflow
    5. Configuration data
      1. Hardcoded data
      2. Parameter-based data
      3. Hashtable data
    6. Local Configuration Manager
      1. LCM settings
        1. Configuration modes
          1. ApplyOnly
          2. ApplyAndMonitor
          3. ApplyAndAutoCorrect
        2. Refresh modes
      2. The LCM configuration
      3. An example LCM configuration
    7. The DSC pull server
      1. What is a DSC pull server?
      2. What does the pull server do for us?
        1. Automatic and continuous configuration
        2. Repository
        3. Reporting
        4. Security
      3. Setting up a DSC pull server
        1. Pull server settings
        2. Installing the DSC server
        3. Adding MOF files to a pull server
        4. Adding DSC resources to a pull server
    8. Deployment considerations
      1. General observations
      2. LCM gotchas
      3. Deployment mode differences
    9. Summary
  4. DSC Configuration Files
    1. Defining a DSC configuration script file
      1. Authoring DSC configuration files
      2. DSC automatic variables
        1. AllNodes
        2. Node
        3. ConfigurationData
      3. DSC resource import declarations
        1. Import-DSCResource
      4. DSC configuration syntax
        1. The configuration keyword
        2. The Node keyword
        3. DSC resource statements
        4.  DSC configuration script file example
    2. Defining a DSC configuration data file
      1.  Authoring DSC configuration data files
      2. Configuration data syntax
        1. The variable syntax
        2. The data file syntax
      3. Allowable DSC configuration content
    3. Creating reusable DSC configurations
      1. Nested DSC configurations
        1. Nested DSC configuration syntax
        2. Nested DSC configuration limitations
      2. DSC composite resources
        1. Why use DSC composite resources?
        2. The DSC composite resource syntax
        3. The  DSC composite resource folder structure
        4. DSC composite resource drawbacks
      3. Partial DSC configurations
    4. Debugging and troubleshooting configuration script files
      1. Status at a glance
      2. Using DSC event logs
        1. Enabling verbose logging
        2. What do DSC event logs contain?
        3. Gathering events from a single DSC operation
          1. Event Viewer
          2. PowerShell
      3. Using the xDscDiagnostics module to analyze DSC logs
        1. Get-xDSCOperation
        2. Trace-xDSCOperation
      4. Resetting the DSC engine cache
      5. Enabling the debug mode
      6. Fixing a stuck DSC run
    5. Summary
  5. DSC Resources
    1. What are DSC resources?
      1. What makes a good DSC resource
        1. Idempotent
        2. Do one thing well
        3. Reuse code, but don't go overboard
        4. Contribute back
      2. Creating PowerShell MOF-based custom DSC resources
        1. MOF-based DSC resource folder structure
        2. MOF-based DSC resource syntax
          1. The DSC resource definition file
          2. Naming
          3. Versioning
          4. Parameters
          5. Qualifiers
        3. The DSC PowerShell module file
          1. Get-TargetResource
          2. Test-TargetResource
          3. Set-TargetResource
        4. Authoring custom DSC resources
          1. Creating DSC resources manually
          2. Creating DSC resources automatically
      3. Creating PowerShell class-based custom DSC resources
        1. PowerShell classes
        2. Class-based DSC resources
          1. The folder structure of class-based DSC resource
          2. Class-based DSC resource syntax
        3. Advantages of a class-based DSC resource
        4. Disadvantages of a class-based DSC resource
      4. Creating single-instance custom DSC resources
      5. Creating PowerShell custom DSC resources in C#
        1. Create the MOF schema
        2. Create the Visual Studio project
        3. Create the C# cmdlet code
        4. Packaging the C# custom DSC resource
      6. Testing custom DSC resources
        1. Using xDscResourceDesigner
        2. Pester
        3. Microsoft recommendations
      7. How do you find DSC resources?
        1. Microsoft DSC resource Kits
          1. Installing DSC resource Kits
        2. Microsoft PowerShell DSC GitHub repository
          1. Installing DSC resources from GitHub
        3. Microsoft PowerShell Gallery
          1. PackageManagement
          2. Discover DSC resources in the PowerShell Gallery
          3. Installing DSC resources in the PowerShell Gallery
        4. Custom hosting options
          1. Local SMB/network share
          2. NuGet IIS
          3. Third-party NuGet servers
      8. Deploying DSC resources
        1. Deploying DSC resources in a push DSC configuration deployment
        2. Deploying DSC resources in a pull DSC configuration deployment
    2. Summary
  6. Pushing DSC Configurations
    1. Tooling
    2. Setting things up
      1. Test environment
    3. Locally pushing DSC configurations
      1. Setting up the test environment locally
      2. Compiling configurations for local target nodes
      3. Executing configurations for local target nodes
    4. Remotely pushing DSC configurations
      1. Setting up the test environment remotely
      2. Compiling configurations for remote target nodes
      3. Executing configurations for remote target nodes
    5. Things you must consider when pushing DSC configurations
    6. Summary
  7. Pulling DSC Configurations
    1. Creating DSC pull servers
      1. DSC pull server setup considerations
        1. DSC pull server type
        2. The Windows management framework version
      2. Initial setup tasks
        1. Installing required DSC resources
        2. SSL certificates
        3. SMB share creation
        4. Preparing DSC resources for pull server distribution
        5. Miscellaneous tasks
      3. Creating an SMB DSC pull server
      4. Creating an HTTPS DSC pull server
      5. DSC pull server and registration keys
    2. Validating a DSC pull server install
      1. Testing using a web browser
      2. Testing using the command line
    3. Registering target nodes with a DSC pull server
      1. Registering a target node using a configuration ID
      2. Registering a target node using RegistrationKey
    4. Pulling DSC configurations with a DSC pull server
      1. Compiling DSC configurations using ConfigurationIDs
      2. Compiling DSC configurations using RegistrationKeys
      3. Deploying DSC Configurations to the DSC pull server
    5. DSC pull server and target node status
      1. Checking the current LCM configuration status
      2. Triggering a DSC configuration to run on a target node
        1. Triggering a WMF 4 target node
        2. Triggering a WMF 5 target node
      3. Using DSC logging to check on the status
      4. Reporting on the target node status
      5. Reporting on the target node status with the DSC pull server
        1. WMF 5 pull server reporting
        2. WMF 4 pull server reporting
    6. Summary
  8. DSC Cross Platform Support
    1. DSC cross-platform support
      1. Using DSC on Linux
        1. Installing DSC on Linux
        2. Pushing a DSC configuration to a Linux node
      2. PowerShell Core
        1. Installing PowerShell Core on Windows
        2. Installing PowerShell Core on macOS
          1. Homebrew
          2. Manual
        3. Installing PowerShell Core on Linux
          1. Ubuntu
    2. Summary
  9. Example Scenarios
    1. Real-life DSC usage
    2. Setting up a common installation base
    3. Installing software
    4. Configuration management refresher
    5. Complicated deployments
    6. Handling change
    7. Summary

Product information

  • Title: Learning PowerShell DSC - Second Edition
  • Author(s): James Pogran
  • Release date: September 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781787287242