Reader small image

You're reading from  Learning PowerShell DSC. - Second Edition

Product typeBook
Published inSep 2017
Publisher
ISBN-139781787287242
Edition2nd Edition
Concepts
Right arrow
Author (1)
James Pogran
James Pogran
author image
James Pogran

James Pogran has been working with computers in one way or another for over 15 years. His first job involved systems administration for a large military installation. He then moved on to develop monitoring software and automate large-scale Windows environments for a major managed services provider. He is currently a senior software engineer at Puppet, Inc where he helps to make Windows automation even better with Puppet.
Read more about James Pogran

Right arrow

DSC Resources

"You must do the thing you think you cannot do."
- Eleanor Roosevelt

In this chapter, you will learn the definition and syntax of a DSC resource. This entails both the code/syntactic elements as well as the folder structure and placement. We will spend significant time covering the purpose of a DSC resource and best practices to develop custom DSC resources; we'll do this by showing examples of badly authored DSC resources and working on them until they are well-defined DSC resources. We will then explain class-based DSC resource differences and how you should handle them compared to their V4 counterparts.

In this chapter, we will cover the following topics:

  • What are DSC resources?
  • How do you find DSC resources?
  • Creating a PowerShell MOF-based DSC resource.
  • Creating a PowerShell class-based DSC resource.
...

What are DSC resources?

DSC resources are PowerShell modules that contain both the schema and implementation to determine and set the target node state. The schema is defined in MOF files, and the implementation code is defined in PowerShell script modules. Beginning with PowerShell V5, DSC resources can also be implemented using only PowerShell script files.

This is all well and good for a definition, but we are getting ahead of ourselves. At its simplest definition, a DSC resource is a PowerShell script that can be run against a target node that only changes the system state when it differs from the desired state. Schema MOFs and module folders aside, the core of a DSC resource is the idempotent code that determines the state of the target node and adjusts it until it is in line with what is expected. This code is implemented in PowerShell, so you're already familiar with...

Summary

In this chapter, we covered the DSC resource structure, syntax, and definitions. We covered how to find DSC resources to fit our needs and how to author useful DSC resources if we do not find what we need. We covered the differences between PowerShell V4 and class-based DSC resources and some reasons you will probably want to move toward class-based DSC resources sooner rather than later.

In the next chapter, we will cover the first way to actually execute DSC configuration scripts: the DSC push model.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning PowerShell DSC. - Second Edition
Published in: Sep 2017Publisher: ISBN-13: 9781787287242
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
James Pogran

James Pogran has been working with computers in one way or another for over 15 years. His first job involved systems administration for a large military installation. He then moved on to develop monitoring software and automate large-scale Windows environments for a major managed services provider. He is currently a senior software engineer at Puppet, Inc where he helps to make Windows automation even better with Puppet.
Read more about James Pogran