You are previewing Learning PowerShell DSC.
O'Reilly logo
Learning PowerShell DSC

Book Description

Get started with the fundamentals of PowerShell DSC and utilize its power to automate deployment and configuration of your servers

About This Book

  • Create flexible and maintainable deployments using DSC configuration scripts that stand the test of time

  • Explore the in depth details of the core architecture, concepts, and practices used by PowerShell DSC

  • A step-by-step guide that shows you how to start using and taking advantage of PowerShell DSC

  • Who This Book Is For

    This book is intended for system administrators, developers, or engineers who are responsible for configuration management and automation and wish to learn PowerShell Desired State Configuration for efficient management, configuration and deployment of systems and applications.

    What You Will Learn

  • Understand configuration management and why you need it

  • Craft flexible, reusable, and maintainable configuration scripts for thousands of servers

  • Create custom DSC resources to manage any application or server setting

  • Apply configuration data to deploy applications to different environments

  • Utilize DSC push deployments to test your configuration scripts and custom DSC resources

  • Install, configure and use DSC pull servers

  • Run a Windows MSI package

  • Deploy a website

  • In Detail

    Windows PowerShell is a task-based command-line shell and scripting language designed especially for system administration. PowerShell DSC is a new management platform that enables you to deploy and manage configuration data for software services and manage the environment in which these services run.

    This book begins with an overview of the basics of PowerShell DSC by covering the architecture and components of the Desired Sate Configuration. It will then familiarize you with the set of PowerShell language extensions and new PowerShell commands. It will help you understand and create DSC configurations with the help of practical examples, and to create DSC custom resources for your custom applications. Finally, you will learn to deploy a real world application using PowerShell DSC. By the end of the book, you will have better knowledge about the powerful Desired State Configuration platform, which helps you to achieve continuous delivery, and efficient management and easy deployment of data for systems.

    Style and approach

    This book is an in-depth guide to using PowerShell DSC, full of real-world experiences and best practices using PowerShell DSC. The topics are explained and build on one another other to provide a holistic learning experience. At the end, all the features learned will be used to create a real world application deployment using DSC.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. Learning PowerShell DSC
      1. Table of Contents
      2. Learning PowerShell DSC
      3. Credits
      4. About the Author
      5. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
          3. Instant updates on new Packt books
      7. 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
      8. 1. Introduction to 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. A high level overview of DSC
          1. The authoring phase
          2. The staging phase
          3. The execution phase
        5. Why all the abstraction?
        6. How does DSC help me?
          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. The 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. The 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. Summary
      9. 2. 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
      10. 3. 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. The DSC script file syntax
            1. The Configuration keyword
            2. The Node keyword
            3. DSC Resource statements
            4. The 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. DSC composite resource folder structure
            4. DSC composite resource drawbacks
        4. Debugging and troubleshooting configuration script files
          1. 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
          2. Using the xDscDiagnostics module to analyze DSC logs
            1. Get-xDscOperation
            2. Trace-xDscOperation
          3. Resetting the DSC engine cache
          4. Enabling the debug mode
          5. Fixing a stuck DSC run
        5. Summary
      11. 4. DSC Resources
        1. What are DSC Resources?
        2. Creating a custom PowerShell v4 DSC Resource
          1. The folder structure of a v4 DSC Resource
          2. The syntax of a v4 DSC Resource
            1. The DSC Resource definition file
              1. Naming
              2. Versioning
              3. Parameters
                1. Qualifiers
            2. The DSC PowerShell module file
              1. Get-TargetResource
              2. Test-TargetResource
              3. Set-TargetResource
          3. Authoring custom DSC Resources
            1. Creating DSC Resources manually
            2. Creating DSC Resources automatically
        3. Creating a custom PowerShell v5 DSC Resource
          1. PowerShell classes
          2. Class-based DSC Resources
          3. The folder structure of v5 DSC Resources
          4. The syntax of v5 DSC Resources
            1. Declaring the class
            2. Schema
            3. Methods
              1. Get
              2. Test
              3. Set
          5. The advantages of a class-based DSC Resource
          6. The disadvantages of a class-based DSC Resource
        4. What makes a good DSC Resource
          1. Idempotent
          2. Do one thing well
          3. Reuse code, but don't go overboard
          4. Contribute back!
        5. Testing custom DSC Resources
          1. Using xDscResourceDesigner
          2. Pester
          3. Microsoft recommendations
        6. How do you find DSC Resources?
          1. Microsoft DSC Resource Kits
            1. Installing DSC Resource Kits
          2. The Microsoft PowerShell DSC GitHub repository
            1. Installing DSC Resources from GitHub
          3. The Microsoft PowerShell Gallery
            1. PackageManagement
              1. Installing PackageManagement
              2. Initializing 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
        7. Summary
      12. 5. Pushing DSC Configurations
        1. Tooling
        2. Setting things up
          1. Test environments
        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
      13. 6. Pulling DSC Configurations
        1. Creating DSC Pull Servers
          1. DSC Pull Server setup considerations
            1. DSC Pull Server types
            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 a WMF 4 DSC Pull Server
          4. Creating a WMF 5 DSC Pull Server
        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 WMF 4 target node
          2. Registering a WMF 5 target node
        4. Pulling DSC configurations with a DSC Pull Server
          1. Pulling DSC configurations using ConfigurationIDs
          2. Pulling DSC configurations using RegistrationKeys
        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
        6. Summary
      14. 7. Example Scenarios
        1. Real life DSC usage
        2. Setting up a common installation base
        3. Installing software
        4. A configuration management refresher
        5. Complicated deployments
        6. Handling change
        7. Summary
      15. Index