Powershell 4.0 – Desired State Configuration
If you’re like most Systems Admins you look for ways you can automate processes and build a more proactive and self-healing environment. There are many applications out there which can be used to automate and orchestrate your environment. Some of the most common are: Puppet, Chef, Ansible and Salt. While all of these are very robust applications, there are some downsides if you are a windows heavy shop. All of them have a pretty steep learning curve and require some sort of in-depth training to really comprehend and utilize them. Secondly, although they all may integrate with windows, sometimes it’s not as easy and out of the box as we really would like. Let’s be honest, not many of us have the time to fully test and train on a new product while still trying to keep our company up and running.
Powershell 4.0 brings a new set of cmdlets and keywords to help you automate processes and tasks in your windows environments. If you know powershell, you’ve done the heavy lifting already so there’s no major learning curve. It will also make the financial guys happy when you aren’t begging for piles of money to implement a new product and then get training before you can fully utilize it. I’ve tried several of the big named IT automation applications, and although I found that some of them could be really amazing, I was left having to do all kinds of extra work and training to really get the most out of them at a Windows heavy company.
OK, so some may ask what really does desired state configuration mean? In simple terms: we set a “state” in which we define how we may want a service, registry key or application to be. We then use that state to constantly check or environment to make sure the machines are in the state we want them to be in. In short it’s 3 steps: 1) set state 2)check state 3)fix state if needed. Granted this is a very abbreviated synopsis of the process, but at the root it’s really not much more complicated.
So why would be use Powershell DSC? To automate and configure server/workstation states with minimal effort. Here are some examples of the types of things we can do:
- Manage registry settings
- Manage Processes and Services
- Deploy Software
- Manage User Accounts and Groups
- Run Scripts
- Manage Server Roles and Features
- Manage Files and Folders
- Fix machines that are no longer in our desired state
- Check configuration and states of machines
Powershell DSC can be a very powerful tool and allow you to become a more proactive systems administrator. So let me give you a really quick example to allow you to see the process. In this example we will ensure the DNS Server windows feature is installed. If you need a full list of windows features, you can run the Get-WindowsFeature command from powershell.
- Step 1A: Define the Configuration
- Step 1B: Call the Function
- Step 2: Applying the Configuration
- Step 3: Detect Configuration Drift
That’s it! Short, sweet and simple. This example is very basic but it should give you an understanding of how easy it is to use Powershell DSC. Be on the lookout for more posts on DSC and the best way to learn is go out there and play around with it.